2013-06-06 32 views
1

我使用了mathworks网站的示例代码,通过a link将MATLAB代码与C/C++集成在一起!MATLAB代码和C/C++集成的致命错误

正如你在代码中看到,有头文件为: #include "engine.h"

在Linux操作系统(Ubuntu的),我跑: g++ engdemo.cpp -o mycpp命令来创建一个可执行程序,但发生以下致命错误:

engdemo.cpp:14:20: fatal error: engine.h: No such file or directory, compilation terminated.

我该如何解决这个致命错误?

+0

是否'engine.h'文件存在于当前目录? –

+0

@BlueBit:你需要告诉编译器在哪里可以找到头文件。您还需要链接所需的库。文档解释了这一点:http://www.mathworks.com/help/matlab/matlab_external/compiling-engine-applications-with-the-mex-command.html,http://www.mathworks.com/support/solutions/en/data/1-1BSZR/ – Amro

回答

2

查找范围

[matlabroot '/extern/include'] 

如果你看到engine.h那里,只是运行

g++ -I../../include engdemo.cpp -o mycpp 

(假设你从[matlabroot '/extern/examples/eng_mat/']运行)

+0

运行时出错:g ++ -I/usr/local/MATLAB/R2011b/extern/include engdemo.cpp -o mycpp: /tmp/ccNSRT82.o:在函数' (.text + 0xa7):未定义的引用'mxCreateDoubleMatrix' engdemo.cpp :(。text + 0xb7):'undec'引用'engOpen' engdemo.cpp :(。 (.text + 0x141):未定义引用'engPutVariable' engdemo.cpp :(。text + 0x155):未定义引用'engEvalString' engdemo.cpp :(。文本+ 0x169):未定义引用'engEvalString' engdemo.cpp :(。text + 0x17d):未定义引用'engEvalString'... – BlueBit

+0

@BlueBit:参见http://stackoverflow.com/questions/7757613/calling-matlab-from-c –