解决In function `mwException::mwException()': undefined reference to `mclcppCreateError'
2015-02-01 20:46
1511 查看
在进行这个实验中,通过c++调用matlab中自己编写的函数(是通过将该函数在matlab中mcc编译成.so,然后c++中调用这个.so的方式),报错记录总结。
实验环境:Ubuntu 12.04.5 64bit, gcc 4.6, matlab 2012a。
上述错误中后面一半是因为缺少库libmwmclmcrrt.so,解决方法就是编译时加一个选项-lmwmclmcrrt,如下:
可见错误少了一半,但是还有很多错误,这些余下的错误都是因为缺少一个包:libmwmclmcr.so,这个包和前面一个包名字很相似,别混了。解决方法就是编译时加选项:-lmwmclmcr,如下(虽然这个错误消失了,但是有一个新警告,并接着很多函数找不到,如下):
这个警告很好解决,只需要链接一下就行,如下:
虽然编译成功了,但是执行不了,报错:
这是因为动态链接库只是一些链接,运行时需要把matlab的动态库装一下,才能让这些链接找到那个库文件。需要安装“MCRInstaller”(安装步骤点此),才可以正常调用。
安装完以后,根据页面中提示将MCRInstaller的一长串路径添加到系统变量的LD_LIBRARY_PATH中就行。调用成功结果如下
实验环境:Ubuntu 12.04.5 64bit, gcc 4.6, matlab 2012a。
<span style="font-size:12px;">$ g++ -o main -I. -L. -L/opt/MATLAB/R2012a/runtime/glnxa64 main.cpp -lmyFunc /usr/bin/ld: warning: libmwmclmcrrt.so.7.17, needed by ./libmyFunc.so, not found (try using -rpath or -rpath-link) /tmp/cci4LSpW.o: In function `main': main.cpp:(.text+0x18b): undefined reference to `mclTerminateApplication_proxy' /tmp/cci4LSpW.o: In function `mwException::mwException()': main.cpp:(.text._ZN11mwExceptionC2Ev[_ZN11mwExceptionC5Ev]+0x41): undefined reference to `mclcppCreateError' /tmp/cci4LSpW.o: In function `mwException::mwException(char const*)': main.cpp:(.text._ZN11mwExceptionC2EPKc[_ZN11mwExceptionC5EPKc]+0x55): undefined reference to `mclcppCreateError' /tmp/cci4LSpW.o: In function `mwException::mwException(error_info*, bool)': main.cpp:(.text._ZN11mwExceptionC2EP10error_infob[_ZN11mwExceptionC5EP10error_infob]+0x5e): undefined reference to `ref_count_obj_addref' main.cpp:(.text._ZN11mwExceptionC2EP10error_infob[_ZN11mwExceptionC5EP10error_infob]+0x75): undefined reference to `mclcppCreateError' /tmp/cci4LSpW.o: In function `mwException::~mwException()': main.cpp:(.text._ZN11mwExceptionD2Ev[_ZN11mwExceptionD5Ev]+0x33): undefined reference to `ref_count_obj_release' /tmp/cci4LSpW.o: In function `mwException::what() const': main.cpp:(.text._ZNK11mwException4whatEv[mwException::what() const]+0x25): undefined reference to `error_info_get_message' /tmp/cci4LSpW.o: In function `mwException::raise_error()': main.cpp:(.text._ZN11mwException11raise_errorEv[mwException::raise_error()]+0x1b): undefined reference to `mclcppGetLastError' /tmp/cci4LSpW.o: In function `mwArray::mwArray(unsigned long, unsigned long, mxClassID, mxComplexity)': main.cpp:(.text._ZN7mwArrayC2Emm9mxClassID12mxComplexity[_ZN7mwArrayC5Emm9mxClassID12mxComplexity]+0x4f): undefined reference to `mclGetMatrix' /tmp/cci4LSpW.o: In function `mwArray::~mwArray()': main.cpp:(.text._ZN7mwArrayD2Ev[_ZN7mwArrayD5Ev]+0x23): undefined reference to `ref_count_obj_release' /tmp/cci4LSpW.o: In function `mwArray::mwArray(array_ref*, bool)': main.cpp:(.text._ZN7mwArrayC2EP9array_refb[_ZN7mwArrayC5EP9array_refb]+0x7d): undefined reference to `ref_count_obj_addref' /tmp/cci4LSpW.o: In function `mwArray::GetPromoted(unsigned long, ...)': main.cpp:(.text._ZN7mwArray11GetPromotedEmz[mwArray::GetPromoted(unsigned long, ...)]+0xa6): undefined reference to `array_ref_getV_int' /tmp/cci4LSpW.o: In function `mwArray::SetData(double*, unsigned long)': main.cpp:(.text._ZN7mwArray7SetDataEPdm[mwArray::SetData(double*, unsigned long)]+0x2b): undefined reference to `array_ref_set_numeric_mxDouble' /tmp/cci4LSpW.o: In function `mwArray::operator double() const': main.cpp:(.text._ZNK7mwArraycvdEv[mwArray::operator double() const]+0x24): undefined reference to `array_ref_get_numeric_mxDouble' ./libmyFunc.so: undefined reference to `mclFreeStackTrace_proxy' ./libmyFunc.so: undefined reference to `ref_count_obj_release_proxy' ./libmyFunc.so: undefined reference to `array_buffer_set_proxy' ./libmyFunc.so: undefined reference to `mclWrite_proxy' ./libmyFunc.so: undefined reference to `array_buffer_get_proxy' ./libmyFunc.so: undefined reference to `array_buffer_add_proxy' ./libmyFunc.so: undefined reference to `mclGetEmbeddedCtfStream_proxy' ./libmyFunc.so: undefined reference to `mclcppCreateError_proxy' ./libmyFunc.so: undefined reference to `mclcppGetArrayBuffer_proxy' ./libmyFunc.so: undefined reference to `mclDestroyStream_proxy' ./libmyFunc.so: undefined reference to `mclcppGetLastError_proxy' ./libmyFunc.so: undefined reference to `array_buffer_to_cell_proxy' ./libmyFunc.so: undefined reference to `mclGetStackTrace_proxy' ./libmyFunc.so: undefined reference to `array_ref_number_of_elements_proxy' ./libmyFunc.so: undefined reference to `mclFeval_proxy' ./libmyFunc.so: undefined reference to `mclmcrInitialize_proxy' ./libmyFunc.so: undefined reference to `mclTerminateInstance_proxy' ./libmyFunc.so: undefined reference to `ref_count_obj_addref_proxy' ./libmyFunc.so: undefined reference to `error_info_get_message_proxy' ./libmyFunc.so: undefined reference to `mclcppFeval_proxy' ./libmyFunc.so: undefined reference to `mclInitializeComponentInstanceEmbedded_proxy' ./libmyFunc.so: undefined reference to `array_ref_classID_proxy' ./libmyFunc.so: undefined reference to `array_ref_getV_int_proxy' collect2: ld returned 1 exit status</span>
上述错误中后面一半是因为缺少库libmwmclmcrrt.so,解决方法就是编译时加一个选项-lmwmclmcrrt,如下:
<span style="font-size:12px;">$ g++ -o main -I. -L. -L/opt/MATLAB/R2012a/runtime/glnxa64 main.cpp -lmyFunc -lmwmclmcrrt /tmp/cc5szYKi.o: In function `mwException::mwException()': main.cpp:(.text._ZN11mwExceptionC2Ev[_ZN11mwExceptionC5Ev]+0x41): undefined reference to `mclcppCreateError' /tmp/cc5szYKi.o: In function `mwException::mwException(char const*)': main.cpp:(.text._ZN11mwExceptionC2EPKc[_ZN11mwExceptionC5EPKc]+0x55): undefined reference to `mclcppCreateError' /tmp/cc5szYKi.o: In function `mwException::mwException(error_info*, bool)': main.cpp:(.text._ZN11mwExceptionC2EP10error_infob[_ZN11mwExceptionC5EP10error_infob]+0x5e): undefined reference to `ref_count_obj_addref' main.cpp:(.text._ZN11mwExceptionC2EP10error_infob[_ZN11mwExceptionC5EP10error_infob]+0x75): undefined reference to `mclcppCreateError' /tmp/cc5szYKi.o: In function `mwException::~mwException()': main.cpp:(.text._ZN11mwExceptionD2Ev[_ZN11mwExceptionD5Ev]+0x33): undefined reference to `ref_count_obj_release' /tmp/cc5szYKi.o: In function `mwException::what() const': main.cpp:(.text._ZNK11mwException4whatEv[mwException::what() const]+0x25): undefined reference to `error_info_get_message' /tmp/cc5szYKi.o: In function `mwException::raise_error()': main.cpp:(.text._ZN11mwException11raise_errorEv[mwException::raise_error()]+0x1b): undefined reference to `mclcppGetLastError' /tmp/cc5szYKi.o: In function `mwArray::mwArray(unsigned long, unsigned long, mxClassID, mxComplexity)': main.cpp:(.text._ZN7mwArrayC2Emm9mxClassID12mxComplexity[_ZN7mwArrayC5Emm9mxClassID12mxComplexity]+0x4f): undefined reference to `mclGetMatrix' /tmp/cc5szYKi.o: In function `mwArray::~mwArray()': main.cpp:(.text._ZN7mwArrayD2Ev[_ZN7mwArrayD5Ev]+0x23): undefined reference to `ref_count_obj_release' /tmp/cc5szYKi.o: In function `mwArray::mwArray(array_ref*, bool)': main.cpp:(.text._ZN7mwArrayC2EP9array_refb[_ZN7mwArrayC5EP9array_refb]+0x7d): undefined reference to `ref_count_obj_addref' /tmp/cc5szYKi.o: In function `mwArray::GetPromoted(unsigned long, ...)': main.cpp:(.text._ZN7mwArray11GetPromotedEmz[mwArray::GetPromoted(unsigned long, ...)]+0xa6): undefined reference to `array_ref_getV_int' /tmp/cc5szYKi.o: In function `mwArray::SetData(double*, unsigned long)': main.cpp:(.text._ZN7mwArray7SetDataEPdm[mwArray::SetData(double*, unsigned long)]+0x2b): undefined reference to `array_ref_set_numeric_mxDouble' /tmp/cc5szYKi.o: In function `mwArray::operator double() const': main.cpp:(.text._ZNK7mwArraycvdEv[mwArray::operator double() const]+0x24): undefined reference to `array_ref_get_numeric_mxDouble' collect2: ld returned 1 exit status</span>
可见错误少了一半,但是还有很多错误,这些余下的错误都是因为缺少一个包:libmwmclmcr.so,这个包和前面一个包名字很相似,别混了。解决方法就是编译时加选项:-lmwmclmcr,如下(虽然这个错误消失了,但是有一个新警告,并接着很多函数找不到,如下):
<span style="font-size:12px;">$ g++ -o main -I. -L. -L/opt/MATLAB/R2012a/runtime/glnxa64 main.cpp -lmyFunc -lmwmclmcrrt -lmwmclmcr /usr/bin/ld: warning: libXm.so.3, needed by /opt/MATLAB/R2012a/bin/glnxa64/libmwuix.so, not found (try using -rpath or -rpath-link) /opt/MATLAB/R2012a/bin/glnxa64/libmwuix.so: undefined reference to `_XmMsgTextIn_0000' /opt/MATLAB/R2012a/bin/glnxa64/libmwuix.so: undefined reference to `_XmPrimitiveHelp' /opt/MATLAB/R2012a/bin/glnxa64/libmwuix.so: undefined reference to `_XmGetAudibleWarning' /opt/MATLAB/R2012a/bin/glnxa64/libmwuix.so: undefined reference to `XmFontListEntryGetTag' /opt/MATLAB/R2012a/bin/glnxa64/libmwuix.so: undefined reference to `XmTransferValue' /opt/MATLAB/R2012a/bin/glnxa64/libmwuix.so: undefined reference to `_XmTextIn_XmTextEventBindings1' /opt/MATLAB/R2012a/bin/glnxa64/libmwuix.so: undefined reference to `XmImSetFocusValues' /opt/MATLAB/R2012a/bin/glnxa64/libmwuix.so: undefined reference to `_XmMsgTextF_0000' /opt/MATLAB/R2012a/bin/glnxa64/libmwuix.so: undefined reference to `XmListSelectPos' /opt/MATLAB/R2012a/bin/glnxa64/libmwuix.so: undefined reference to `XmFontListNextEntry' /opt/MATLAB/R2012a/bin/glnxa64/libmwhg.so: undefined reference to `XmCreateSeparatorGadget' /opt/MATLAB/R2012a/bin/glnxa64/libmwuix.so: undefined reference to `_XmConvertComplete' /opt/MATLAB/R2012a/bin/glnxa64/libmwuix.so: undefined reference to `XmMenuPosition' /opt/MATLAB/R2012a/bin/glnxa64/libmwuix.so: undefined reference to `_XmTextIn_XmTextEventBindings2' /opt/MATLAB/R2012a/bin/glnxa64/libmwuix.so: undefined reference to `XmCreatePulldownMenu' /opt/MATLAB/R2012a/bin/glnxa64/libmwhg.so: undefined reference to `XmTextGetLastPosition' /opt/MATLAB/R2012a/bin/glnxa64/libmwuix.so: undefined reference to `XmListDeselectAllItems' /opt/MATLAB/R2012a/bin/glnxa64/libmwuix.so: undefined reference to `XmStringExtent' /opt/MATLAB/R2012a/bin/glnxa64/libmwuix.so: undefined reference to `XmListItemPos' /opt/MATLAB/R2012a/bin/glnxa64/libmwuix.so: undefined reference to `_XmMgrTraversal' /opt/MATLAB/R2012a/bin/glnxa64/libmwuix.so: undefined reference to `XmQmotif' ......</span>
这个警告很好解决,只需要链接一下就行,如下:
<span style="font-size:12px;">$ locate libXm /opt/MATLAB/R2012a/sys/os/glnxa64/libXm.so.3 /opt/MATLAB/R2012a/sys/os/glnxa64/libXm.so.3.0.2 /usr/lib/x86_64-linux-gnu/libXmu.a /usr/lib/x86_64-linux-gnu/libXmu.so /usr/lib/x86_64-linux-gnu/libXmu.so.6 /usr/lib/x86_64-linux-gnu/libXmu.so.6.2.0 /usr/lib/x86_64-linux-gnu/libXmuu.a /usr/lib/x86_64-linux-gnu/libXmuu.so /usr/lib/x86_64-linux-gnu/libXmuu.so.1 /usr/lib/x86_64-linux-gnu/libXmuu.so.1.0.0 $ ln -s /opt/MATLAB/R2012a/sys/os/glnxa64/libXm.so.3 /opt/MATLAB/R2012a/bin/glnxa64 $ g++ -o main -I. -L. -L/opt/MATLAB/R2012a/runtime/glnxa64 main.cpp -lmyFunc -lmwmclmcrrt -lmwmclmcr </span>编译成功通过!
虽然编译成功了,但是执行不了,报错:
<span style="font-size:12px;">$ ./main ./main: error while loading shared libraries: libmwmclmcrrt.so.7.17: cannot open shared object file: No such file or directory</span>
这是因为动态链接库只是一些链接,运行时需要把matlab的动态库装一下,才能让这些链接找到那个库文件。需要安装“MCRInstaller”(安装步骤点此),才可以正常调用。
安装完以后,根据页面中提示将MCRInstaller的一长串路径添加到系统变量的LD_LIBRARY_PATH中就行。调用成功结果如下
<span style="font-size:12px;">$ ./main Warning: latest version of matlab app-defaults file not found. Contact your system administrator to have this file installed Please input 2 numbers <a b> and then press enter: 4 4 The sum is: 8</span>
相关文章推荐
- crtbegin_dynamic.o: in function _start:crtbrand.c(.text+0x78): error: undefined reference to 'main
- Dev C++中的错误的解决[Linker error] undefined reference to `__dyn_tls_init_callback'
- cocos2d-x 使用ndk编译 x86 出现 in function Curl_resolv_timeout: undefined reference to 'sigsetjmp' 错误
- gcc 共享库的时候显示.../crt1.o: In function `_start': (.text+0x18): undefined reference to `main'的错误
- error:undefined reference to `coloured_LED_init'及相关错误时的解决办法!
- Dev C++中的错误的解决[Linker error] undefined reference to `__dyn_tls_init_callback'
- Uboot编译出下如下错误的一个原因:In function `__aeabi_ldiv0': (.text+0x8): undefined reference to `raise'
- ffmpeg libx264编译出现error: undefined reference to 'x264_picture_init'等问题的解决方法
- Linux c++ error: undefined reference to 'dlopen' 解决办法
- 编译linux 内核时:decompress.c:(.text+0x25c4): undefined reference to `error'的解决办法
- undefined reference to 'pthread_create'问题解决
- QT 编译出现 undefined reference to `vtable for xx' 的解决方法
- undefined reference to `clock_gettime' 链接错误问题解决
- glibc静态链接 libc.a(nsswitch.o)(.data+0x64):undefined reference to `_nss_files_getaliasent_r' 错误解决方法
- undefined reference to 'pthread_create'问题解决
- Eclipse3.6.1中解决undefined reference to `boost::thread::start_thread()'
- [linux proc] undefined reference to `ECPGget_sqlca' 问题解决
- undefined reference to 'pthread_create'问题解决
- 解决Netbeans 下 undefined reference to `pthread_create'
- 类似undefined reference to 'pthread_create'问题的解决