Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Using C functions in Visual C++

Using C functions in Visual C++

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Geert Craessaerts
    wrote on last edited by
    #1

    Can anyone explain me how to use C functions in Visual C++? Is there something special that I need to know? Thanx, Kind regards, Geert

    _ V 2 Replies Last reply
    0
    • G Geert Craessaerts

      Can anyone explain me how to use C functions in Visual C++? Is there something special that I need to know? Thanx, Kind regards, Geert

      _ Offline
      _ Offline
      _Theo_
      wrote on last edited by
      #2

      If you want to use C code or functions inside your C++ source files use the following: extern "C" { //C code or function calls here }

      1 Reply Last reply
      0
      • G Geert Craessaerts

        Can anyone explain me how to use C functions in Visual C++? Is there something special that I need to know? Thanx, Kind regards, Geert

        V Offline
        V Offline
        Vimal Earnest
        wrote on last edited by
        #3

        Your problem is not clear from the posted message. You can use c functions from Visual C++(Visual C++ is a tool built on c++ and c++ is backward compatible with c ). If you have problems with using c functions from a library(link error most probably), that may be due to the name mangling brought about by the c++ compiler. You can ask the compiler to turn off name mangling for the library functions by doing the following : extern "C" { #include "yourheader.h" } This asks the compiler not to mangle the names in the header file. HTH ~ Vimal

        G J 2 Replies Last reply
        0
        • V Vimal Earnest

          Your problem is not clear from the posted message. You can use c functions from Visual C++(Visual C++ is a tool built on c++ and c++ is backward compatible with c ). If you have problems with using c functions from a library(link error most probably), that may be due to the name mangling brought about by the c++ compiler. You can ask the compiler to turn off name mangling for the library functions by doing the following : extern "C" { #include "yourheader.h" } This asks the compiler not to mangle the names in the header file. HTH ~ Vimal

          G Offline
          G Offline
          Geert Craessaerts
          wrote on last edited by
          #4

          I want to use some functions that are declared in this header file(matrix.h), but when I want to compile my program, it gives the following error. error LNK2001: unresolved external symbol _mxCreateDoubleMatrix error LNK2001: unresolved external symbol _mxGetPr Do you know what's wrong? Kind regards, Geert /* * @(#)matrix.h generated by: makeheader Sun Feb 11 00:59:45 2001 * * built from: ../include/copyright.h * ../include/mxassert.h * alloccbk.c * alloclst.c * array.c * array2.c * arraycbk.c * arraycpy.c * assignmt.c * bytestr.c * catenate.c * cellindex.c * checkdim.c * conversions.c * end.c * errmsg.c * error.c * errtable.c * fcnreg.c * fmxapi.c * funhdl.c * ieee_wrap.c * indexcpy.c * iocbk.c * marshal.c * mcat.c * mxapiv4.c * mxequal.c * mxutil.c * nargchk.c * numconv.c * opaque.c * permute.c * populate.c * referenc.c * resize.c * rndcolon.c * scopemgr.c * strconv.c * transpose.c * txtcmp.c * undoc.c * warning.c * wrnstate.c * modver/modver.c * mxdbg.h */ #ifndef matrix_h #define matrix_h /* $Revision: 1.4 $ */ /* * Copyright (c) 1984-2001 The MathWorks, Inc. * All Rights Reserved. */ /* $Revision: 1.5 $ */ /* mxAssert(int expression, char *error_message) --------------------------------------------- Similar to ANSI C's assert() macro, the mxAssert macro checks the value of an assertion, continuing execution only if the assertion holds. If 'expression' evaluates to be true, then the mxAssert does nothing. If, however, 'expression' is false, then mxAssert prints an error message to the MATLAB Command Window, consisting of the failed assertion's expression, the file name and line number where the failed assertion occurred, and the string 'error_message'. 'error_message' allows the user to specify a more understandable description of why the assertion failed. (Use an empty string if no extra description should follow the failed assertion message.) After a failed assertion, control returns to the MATLAB command line. mxAssertS, (the S for Simple), takes the same inputs as mxAssert. It does not print the text of the failed assertion, only the file and line where the assertion failed, and the explanatory error_message. Note that script MEX will turn off these assertions when bu

          J 1 Reply Last reply
          0
          • G Geert Craessaerts

            I want to use some functions that are declared in this header file(matrix.h), but when I want to compile my program, it gives the following error. error LNK2001: unresolved external symbol _mxCreateDoubleMatrix error LNK2001: unresolved external symbol _mxGetPr Do you know what's wrong? Kind regards, Geert /* * @(#)matrix.h generated by: makeheader Sun Feb 11 00:59:45 2001 * * built from: ../include/copyright.h * ../include/mxassert.h * alloccbk.c * alloclst.c * array.c * array2.c * arraycbk.c * arraycpy.c * assignmt.c * bytestr.c * catenate.c * cellindex.c * checkdim.c * conversions.c * end.c * errmsg.c * error.c * errtable.c * fcnreg.c * fmxapi.c * funhdl.c * ieee_wrap.c * indexcpy.c * iocbk.c * marshal.c * mcat.c * mxapiv4.c * mxequal.c * mxutil.c * nargchk.c * numconv.c * opaque.c * permute.c * populate.c * referenc.c * resize.c * rndcolon.c * scopemgr.c * strconv.c * transpose.c * txtcmp.c * undoc.c * warning.c * wrnstate.c * modver/modver.c * mxdbg.h */ #ifndef matrix_h #define matrix_h /* $Revision: 1.4 $ */ /* * Copyright (c) 1984-2001 The MathWorks, Inc. * All Rights Reserved. */ /* $Revision: 1.5 $ */ /* mxAssert(int expression, char *error_message) --------------------------------------------- Similar to ANSI C's assert() macro, the mxAssert macro checks the value of an assertion, continuing execution only if the assertion holds. If 'expression' evaluates to be true, then the mxAssert does nothing. If, however, 'expression' is false, then mxAssert prints an error message to the MATLAB Command Window, consisting of the failed assertion's expression, the file name and line number where the failed assertion occurred, and the string 'error_message'. 'error_message' allows the user to specify a more understandable description of why the assertion failed. (Use an empty string if no extra description should follow the failed assertion message.) After a failed assertion, control returns to the MATLAB command line. mxAssertS, (the S for Simple), takes the same inputs as mxAssert. It does not print the text of the failed assertion, only the file and line where the assertion failed, and the explanatory error_message. Note that script MEX will turn off these assertions when bu

            J Offline
            J Offline
            jhwurmbach
            wrote on last edited by
            #5

            Geert Craessaerts wrote: Do you know what's wrong? You need to link with the library where these functions are in. That means, in the Project-Settings, Tab 'Link', under 'Object/library module', inset the name (maybe with path) of the .lib file.


            My opinions may have changed, but not the fact that I am right.

            1 Reply Last reply
            0
            • V Vimal Earnest

              Your problem is not clear from the posted message. You can use c functions from Visual C++(Visual C++ is a tool built on c++ and c++ is backward compatible with c ). If you have problems with using c functions from a library(link error most probably), that may be due to the name mangling brought about by the c++ compiler. You can ask the compiler to turn off name mangling for the library functions by doing the following : extern "C" { #include "yourheader.h" } This asks the compiler not to mangle the names in the header file. HTH ~ Vimal

              J Offline
              J Offline
              Jambolo
              wrote on last edited by
              #6

              Vimal Earnest wrote: extern "C" { #include "yourheader.h" } This is generally not a good idea. yourheader.h may include other header files that contain C++ code (windows system files, for example). A better way to do it is to put

              #if defined( __cplusplus )
              extern "C" {
              #endif // defined( __cplusplus )

              inside yourheader.h before declarations (but after includes) and

              #if defined( __cplusplus )
              }
              #endif // defined( __cplusplus )

              inside yourheader.h at the end.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups