Unable to compile MEX

2019-08-20 01:48发布

问题:

I am trying to compile some MATLAB MEX files from C++ source. The files I am trying to compile can be found here; I am using Windows XP on a 32-bit system, MATLAB 2012a and have installed the Microsoft Windows SDK v7.1 to use as my compiler.

MATLAB outputs the following error if I try to compile:

>> mex -O -largeArrayDims osc_free_address.c
osc_free_address.c 
osc_free_address.c(1) : error C2059: syntax error : '<' 
osc_free_address.c(37) : error C2015: too many characters in constant 
osc_free_address.c(38) : error C2059: syntax error : '<' 
osc_free_address.c(39) : error C2015: too many characters in constant 
osc_free_address.c(39) : error C2015: too many characters in constant 
osc_free_address.c(39) : error C2015: too many characters in constant 
osc_free_address.c(41) : error C2018: unknown character '0x40' 
osc_free_address.c(43) : error C2015: too many characters in constant 
osc_free_address.c(44) : error C2015: too many characters in constant 
osc_free_address.c(44) : error C2015: too many characters in constant 
osc_free_address.c(44) : error C2015: too many characters in constant 
osc_free_address.c(44) : error C2015: too many characters in constant 
osc_free_address.c(46) : error C2059: syntax error : '<' 
osc_free_address.c(82) : fatal error C1021: invalid preprocessor command 'page' 

  C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: Compile of 'osc_free_address.c' failed. 

Error using mex (line 206)
Unable to complete successfully.

I have used mex -setup to setup my compiler with Microsoft Windows SDK v7.1. Interestingly, although I have them installed on my system, MATLAB doesn't see MS Visual Studio C++ 2008 or 2010. I have also tried compiling with the Lcc-win32 C 2.4.1 compiler (which is recognised by MATLAB), to the same effect as shown above.

I understand that this particular set of C++ source files might require something called liblo to compile (I'm not sure whether this is a requirement at compile-time or run-time); as far as I'm aware I have installed these correctly, but there's a possibility that the problem might lie here too.

Any help would be greatly appreciated.

回答1:

Try renaming your .c files to .cpp and re-compile

>> mex -largeArrayDims -O osc_free_address.cpp

Moreover, why don't you try the build m file that comes with the package (as suggested in this question)?

Have you downloaded and compiled liblo? you might need to add the include path and library path for it in the mex command?

>> mex -largeArrayDims -O -I<liblo include path> -L<liblo lib path> -llo osc_free_address.cpp