Matlab 中使用 C/C++ 或 Fortran 代码的一种方式是利用 mex 进行编译,然后调用。
1 编译器设置
mex -setup
有可能见到的信息是这个样子:
>> mex -setup
Welcome to mex -setup. This utility will help you set up
a default compiler. For a list of supported compilers, see
http://www.mathworks.com/support/compilers/R2012b/win64.html
Please choose your compiler for building MEX-files:
Would you like mex to locate installed compilers [y]/n? y
No supported SDK or compiler was found on this computer.
For a list of supported compilers, see
http://www.mathworks.com/support/compilers/R2012b/win64.html
Error using mex (line 206)
Unable to complete successfully.
Matlab 无法完成自动搜索编译器,可以选择 n 再尝试。
Welcome to mex -setup. This utility will help you set up
a default compiler. For a list of supported compilers, see
http://www.mathworks.com/support/compilers/R2012b/win64.html
Please choose your compiler for building MEX-files:
Would you like mex to locate installed compilers [y]/n? n
Select a compiler:
[1] Intel C++ 12.0 (with Microsoft Software Development Kit (SDK) linker)
[2] In

本文介绍了在Matlab中如何使用MEX调用C/C++或Fortran代码,包括编译器设置、编译文件及调用过程。遇到的主要问题是需要匹配合适的编译器,如Intel Fortran,并可能需要自定义编译脚本。MEX文件本质上是一个导出mexFunction的动态链接库,遵循DLL编译规则。
最低0.47元/天 解锁文章
2804

被折叠的 条评论
为什么被折叠?



