我正在尝试从 C++ 源代码编译一些 MATLAB MEX 文件。我正在尝试编译的文件 can be found here ;我在 32 位系统 MATLAB 2012a 上使用 Windows XP,并安装了 Microsoft Windows SDK v7.1 用作我的编译器。
如果我尝试编译,MATLAB 会输出以下错误:
>> 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.
我已经使用 mex -setup 将我的编译器设置为 Microsoft Windows SDK v7.1。有趣的是,虽然我在我的系统上安装了它们,但 MATLAB 没有看到 MS Visual Studio C++ 2008 或 2010。我还尝试使用 Lcc-win32 C 2.4.1 编译器( 被 MATLAB 识别),与上面所示的效果相同。
我知道这组特定的 C++ 源文件可能需要一个叫做 liblo 的东西编译(我不确定这是编译时还是运行时的要求);据我所知,我已经正确安装了这些,但问题也可能出在这里。
如有任何帮助,我们将不胜感激。
最佳答案
尝试将您的 .c
文件重命名为 .cpp
并重新编译
>> mex -largeArrayDims -O osc_free_address.cpp
另外,要不你试试包里自带的build m文件 (如 this question 中所建议)?
你有没有下载编译liblo?您可能需要在 mex
命令中为其添加包含路径和库路径?
>> mex -largeArrayDims -O -I<liblo include path> -L<liblo lib path> -llo osc_free_address.cpp
关于c++ - 无法编译 MEX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14853603/