我的是ubuntu14.04系统,matlab2015b
ubuntu下将cpp转化成mexa64文件,不知为何,文件并没有出现,但是转化之后matlab已经有这个内置函数了,下面直接出方法
这篇参考博客讲的是windows下的http://blog.csdn.net/tiandijun/article/details/50549802
下面方法是linux下的
比如我们的cpp文件是helloword.cpp
首先在matlab的命令窗口输入
mex -setup然后会出现一系列提示,ubuntu的如下:
MEX configured to use 'gcc' for C language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. In the near future
you will be required to update your code to utilize the
new API. You can find more information about this at:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
To choose a different language, select one from the following:
mex -setup C++
mex -setup FORTRAN
点击 mex -setup C++使用g++来编译
然后会提示
MEX configured to use 'g++' for C++ language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. In the near future
you will be required to update your code to utilize the
new API. You can find more information about this at:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
然后直接在命令窗口输入
mex 路径/helloword.cpp就行,注意是绝对路径
不报错就编译成功了,这时候就可以在matlab里输入 helloword了,不知道为啥我并没有出现mexa64文件,不过helloword这个函数以及被安置到matlab内置函数中了,
这篇博客提到了一个小例子,可以参考