在Ubuntu中,c++调用matlab引擎(
入门实例点这里),已经设置好了库文件的查找路径,但是编译时还是报错:
$ g++ matlab_eigen.cpp -o matlab_eigen -I/opt/MATLAB/R2012a/extern/include -L/opt/MATLAB/R2012a/bin/glnxa64
/tmp/cccXS6eb.o: In function `main':
matlab_eigen.cpp:(.text+0xe): undefined reference to `engOpen'
matlab_eigen.cpp:(.text+0x52): undefined reference to `engEvalString'
matlab_eigen.cpp:(.text+0x63): undefined reference to `engEvalString'
matlab_eigen.cpp:(.text+0x74): undefined reference to `engEvalString'
matlab_eigen.cpp:(.text+0x85): undefined reference to `engEvalString'
collect2: ld returned 1 exit status
原因:缺少需要的链接库:
在windows下:libeng.lib libmx.lib libmex.lib libmat.lib (依次对应
$ g++ matlab_eigen.cpp -o matlab_eigen -I/opt/MATLAB/R2012a/extern/include -L/opt/MATLAB/R2012a/bin/glnxa64
/tmp/cccXS6eb.o: In function `main':
matlab_eigen.cpp:(.text+0xe): undefined reference to `engOpen'
matlab_eigen.cpp:(.text+0x52): undefined reference to `engEvalString'
matlab_eigen.cpp:(.text+0x63): undefined reference to `engEvalString'
matlab_eigen.cpp:(.text+0x74): undefined reference to `engEvalString'
matlab_eigen.cpp:(.text+0x85): undefined reference to `engEvalString'
collect2: ld returned 1 exit status
原因:缺少需要的链接库:
在windows下:libeng.lib libmx.lib libmex.lib libmat.lib (依次对应

在Ubuntu系统中尝试编译包含MATLAB eigen的项目时,遇到`undefined reference to `engOpen'`错误。问题源于链接阶段未能正确引用libeng.so库。确保在编译命令中使用 `-leng` 而不是 `-llibeng`,因为Linux系统不需要`lib`前缀。同时,要注意MATLAB库在Windows和Linux之间的不兼容性,避免混淆库文件。正确的编译命令应为:`g++ matlab_eigen.cpp -o matlab_eigen -I/opt/MATLAB/R2012a/extern/include -L/opt/MATLAB/R2012a/bin/glnxa64 -leng -lmx`。
最低0.47元/天 解锁文章
2165

被折叠的 条评论
为什么被折叠?



