C++ 尝试编译多个c++;MATLAB的mex文件
我正在Ubuntu下使用MATLAB,想用mex编译一组带有头文件的2个c++文件。我展示了一个基本的例子和我得到的错误 这个代码从C++函数中产生文本“hello”,从MeXFECT开始,用Max(MeX MpExyAlx.CPP)在Matlab中编译: 然后是新函数的文件C++ 尝试编译多个c++;MATLAB的mex文件,c++,matlab,compiler-errors,header-files,mex,C++,Matlab,Compiler Errors,Header Files,Mex,我正在Ubuntu下使用MATLAB,想用mex编译一组带有头文件的2个c++文件。我展示了一个基本的例子和我得到的错误 这个代码从C++函数中产生文本“hello”,从MeXFECT开始,用Max(MeX MpExyAlx.CPP)在Matlab中编译: 然后是新函数的文件try.cpp: #include <mex.h> #include <iostream> #include <try.h> using namespace std; void newf
try.cpp
:
#include <mex.h>
#include <iostream>
#include <try.h>
using namespace std;
void newfunc(){
cout<<"hello\n";
}
使用-I
选项的另一次尝试:
>> mex -I mexTryAlex.cpp try.cpp try.h
Warning: You are using gcc version "4.4.3-4ubuntu5)". The version
currently supported with MEX is "4.3.4".
For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release/
mexTryAlex.cpp:1:17: error: mex.h: No such file or directory
mexTryAlex.cpp:7: error: ‘mxArray’ has not been declared
mexTryAlex.cpp:7: error: ISO C++ forbids declaration of ‘mxArray’ with no type
mexTryAlex.cpp:7: error: expected ‘,’ or ‘...’ before ‘*’ token
mex: compile of ' "mexTryAlex.cpp"' failed.
??? Error using ==> mex at 208
Unable to complete successfully.
如何编译这些文件?该错误已通过使用修复
#include "try.h"
而不是
#include <try.h>
#包括
在源文件中 只是一个一般性的建议:
使用名称空间std代码>不是最好的想法。只需使用std::cout
,或者如果你经常使用cout
并想将其缩写,请使用使用std::cout代码>,但从长远来看,打开整个std名称空间会让你头疼:)看看这里,了解关于这个主题的利弊/讨论。
>> mex -I mexTryAlex.cpp try.cpp try.h
Warning: You are using gcc version "4.4.3-4ubuntu5)". The version
currently supported with MEX is "4.3.4".
For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release/
mexTryAlex.cpp:1:17: error: mex.h: No such file or directory
mexTryAlex.cpp:7: error: ‘mxArray’ has not been declared
mexTryAlex.cpp:7: error: ISO C++ forbids declaration of ‘mxArray’ with no type
mexTryAlex.cpp:7: error: expected ‘,’ or ‘...’ before ‘*’ token
mex: compile of ' "mexTryAlex.cpp"' failed.
??? Error using ==> mex at 208
Unable to complete successfully.
#include "try.h"
#include <try.h>