我正在尝试编写一个使用libhdf5的matlab mex函数; 我的Linux安装提供了libhdf5-1.8共享库和头文件.但是,我的Matlab版本r2007b提供了1.6版本的libhdf5.so.(matlab .mat文件bootstrap hdf5,显然).当我编译mex时,它在Matlab中会出现段错误.如果我将我的libhdf5版本降级到1.6(不是长期选项),代码编译并运行正常.
问题:我该如何解决这个问题?如何告诉mex编译过程链接/usr/lib64/libhdf5.so.6而不是/opt/matlab/bin/glnxa64/libhdf5.so.0?当我尝试-Wl,-rpath-link,/usr/lib64在我的编译中使用时,我得到的错误如下:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/../../../../x86_64-pc-linux-gnu/bin/ld: warning: libhdf5.so.0, needed by /opt/matlab/matlab75/bin/glnxa64/libmat.so, may conflict with libhdf5.so.6
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
mex: link of 'hdf5_read_strings.mexa64' failed.
make: *** [hdf5_read_strings.mexa64] Error 1
Run Code Online (Sandbox Code Playgroud)
ACK.最后一种方法是下载hdf5-1.6.5标题的本地副本并完成它,但这不是未来的证明(Matlab版本升级是我的未来.).有任何想法吗?
编辑:根据Ramashalanka的优秀建议,我
A)要求mex -v获得3个gcc命令; 最后一个是链接器命令;
B)用a -v来调用该链接器命令来获取collect命令;
C)调用它collect2 -v -t和其余的标志.
我输出的相关部分:
/usr/bin/ld: mode elf_x86_64
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/../../../../lib64/crti.o
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/crtbeginS.o
hdf5_read_strings.o
mexversion.o
-lmx (/opt/matlab/matlab75/bin/glnxa64/libmx.so)
-lmex (/opt/matlab/matlab75/bin/glnxa64/libmex.so)
-lhdf5 (/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/../../../../lib64/libhdf5.so)
/lib64/libz.so
-lm (/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/../../../../lib64/libm.so) …Run Code Online (Sandbox Code Playgroud) 我已经下载了以下代码:
CVPR 2014交叉联合优化代码
cvpr2014-iou-code-1.0.zip
http://research.microsoft.com/en-us/downloads/e164fe21-ef2b-4e34-98c1-4868968abb06/
我得到的是一个包含两个文件夹的存档,一个叫src/,另一个叫matlab/.我正在运行Linux Fedora 19,我可以src/很好地编译代码.当我尝试编译代码时出现问题matlab/.
自述文件说:
Run Code Online (Sandbox Code Playgroud)Matlab compilation ------------------ From within Matlab, configure the compiler using "mex -setup", then adjust the paths in matlab\compile_windows.m or matlab/compile_linux.m scripts and run either "compile_linux.m" or "compile_windows.m" in the "matlab" directory.
更具体地针对Linux:
Run Code Online (Sandbox Code Playgroud)Linux ===== From within Matlab run "mex -setup", then edit the mexopts.sh file and modify the settings CXXFLAGS='-std=c++11 -fopenmp -march=native -D_GNU_SOURCE' CXXLIBS="$RPATH $MLIBS -lm -lgomp" CXXOPTIMFLAGS='-Ofast -DNDEBUG' This will …