简体   繁体   中英

Can't get any #includes to work in Matlab/MEX with Visual Studio C++

I want to do some simulations that need C++-Code in Matlab. This works like a charm, but as soon as I put in some additional #include 's in the C++/MEX-Code I get a ton of error messages like this:

    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\cstdlib(19) : error C2054: expected '(' to follow 'using' 
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\cstdlib(19) : error C2061: syntax error : identifier 'using' 
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\cstdlib(21) : error C2061: syntax error : identifier 'using' 
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\cstdlib(21) : error C2061: syntax error : identifier 'abs' 
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\cstdlib(21) : error C2059: syntax error : ';' 
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\cstdlib(21) : error C2061: syntax error : identifier 'atexit' 
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\cstdlib(22) : error C2061: syntax error : identifier 'atof' 
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\cstdlib(22) : error C2059: syntax error : ';' 
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\cstdlib(22) : error C2061: syntax error : identifier 'atoi' 
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\cstdlib(22) : error C2061: syntax error : identifier 'atol' 
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\cstdlib(23) : error C2061: syntax error : identifier 'bsearch' 
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\cstdlib(23) : error C2059: syntax error : ';' 
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\cstdlib(23) : error C2061: syntax error : identifier 'calloc' 
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\cstdlib(23) : error C2061: syntax error : identifier 'div' 
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\cstdlib(24) : error C2061: syntax error : identifier 'exit' 
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\cstdlib(24) : error C2059: syntax error : ';' 
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\cstdlib(24) : error C2061: syntax error : identifier 'free' 
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\cstdlib(25) : error C2061: syntax error : identifier 'labs' 
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\cstdlib(25) : error C2059: syntax error : ';'
...

I tried different versions of Matlab, Visual Studio and different C++-Compilers. I have code that works perfectly fine and also tried this with example-code from Mathworks that also works fine.

For testing-purposes I simply put #include <random> or include <algorithm> on top of working examples and then those error-messages occur. No "file not found"-errors.

Can anybody give me a hint what I'm doing wrong here? I didn't change anything in mexopts.bat and I believe the right include-directories are in there. Programming in Visual Studio itself works without any problems with those #include 's...

OK, so in hope that other people who run into the same problem have an answer here: My source-files were always *.c - so no C++-files. Changing them to *.cpp solved the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM