Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 尝试编译多个c++;MATLAB的mex文件_C++_Matlab_Compiler Errors_Header Files_Mex - Fatal编程技术网

C++ 尝试编译多个c++;MATLAB的mex文件

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

我正在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 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>