2

私はUbuntu でMATLABを使用しており、 mexを使用してヘッダー ファイルを含む2 つのc++ファイルのセットをコンパイルしたいと考えています。基本的な例と発生しているエラーを示します。

このコードは、mexFunction から始まり、mex を使用して MATLAB でコンパイルされた c++ 関数 (mex mexTryAlex.cpp) からテキスト "hello" を生成します。

#include <mex.h>
#include <iostream>
using namespace std;

void newfunc(){
    cout<<"hello\n";   
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 
{ 
    newfunc();
}

そしてそれは正常に動作します。今、複数のファイルとヘッダー ファイルを mex で使用しようとしています。ヘッダーファイルを作成しますtry.h:

#ifndef try_h
#define try_h
void newfunc();
#endif

そして、新しい関数のファイルtry.cpp:

#include <mex.h>
#include <iostream>
#include <try.h>
using namespace std;

void newfunc(){
    cout<<"hello\n";   
}

これらの 3 つのファイルは、次のものではコンパイルできませんmex

>> mex  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/

try.cpp:4:17: error: try.h: No such file or directory
mex: compile of ' "try.cpp"' failed.
??? Error using ==> mex at 208
Unable to complete successfully.

-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.

これらのファイルをコンパイルするにはどうすればよいですか?

4

1 に答える 1

1

エラーは使用して修正されました

#include "try.h"

それ以外の

 #include <try.h>  

ソースファイルで。

于 2013-04-22T14:44:46.500 に答える