Matlab中编译C/C++程序的步骤:
1、
配置编译器环境
在命令行中输入:mex –setup
>>
mex -setup
Please choose your compiler for
building external interface (MEX) files:
Would you like mex to locate
installed compilers [y]/n? y
Select a compiler:
[1] Lcc-win32 C 2.4.1 in
D:PROGRA~1MATLABR2009asyslcc
[0] None
Compiler:
1
%在这里选择1表示使用的是matlab内置的编译C/C++的环境,若安装有VS或是VC,则也可以用VS或是VC的编译器
Please verify your
choices:
Compiler: Lcc-win32 C
2.4.1
Location:
D:PROGRA~1MATLABR2009asyslcc
Are these correct [y]/n?
y
Trying to update options file:
C:UsersHYAppDataRoamingMathWorksMATLABR2009amexopts.bat
From
template: D:PROGRA~1MATLABR2009abinwin32mexoptslccopts.bat
Done . . .
2、
编译C/C++程序
在命令行中输入:mex 要编译的C/C++的文件名
lcc
preprocessor warning: FtrVal.cpp:15 EOF inside comment
Error
FtrVal.cpp: 14 syntax error; found `end of input'
expecting `;'
1 errors,
1 warnings
D:PROGRA~1MATLABR2009ABINMEX.PL:
Error: Compile of 'FtrVal.cpp' failed.
??? Error
using ==> mex at 218
Unable to
complete successfully.
在这里可能存在的问题是:在C/C++程序(在这里是FtrVal.cpp)中函数名的后面存在着中文的注释。
删除掉函数名的后面的中文注释后,再重新编译,若出现的问题如下:
>>
mex FtrVal.cpp
Specified export _mexFunction is
not defined
Missing exports.
Aborting
D:PROGRA~1MATLABR2009ABINMEX.PL: Error: Link of
'FtrVal.mexw32' failed.
??? Error using ==>
mex at 218
Unable to complete
successfully.
解决办法:查找C/C++程序(在这里是FtrVal.cpp)中是否还有其他的中文注释,若有,则删掉。
出现上述问题的原因:matlab自带的LCC编译器不支持中文注释,而程序中出现了中文注释,所以出现了上述问题。