Using C functions in Visual C++
-
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
-
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
-
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
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
-
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
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
-
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
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.
-
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
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.