繁体   English   中英

使用g ++将32位和64位.so文件链接到c ++程序

[英]Linking both 32bit and 64bit .so files with g++ for a c++ program

我试图同时链接32位和64位.so文件的c ++程序。 我使用64位Ubuntu 12.04.1我也没有重新编译的源文件。

当我运行g ++命令时:

g++ onlineTraining.cpp -I /usr/local/MATLAB/R2012a_Student/extern/include/ -L /home/forest/SoarSuite/out/ -L /usr/local/MATLAB/R2012a_Student/bin/glnx86/ -I /home/forest/SoarSuite/out/include -leng -lmat -lmex -lut -lSoar

我得到以下输出,因为它无法识别32位.so文件:

/usr/bin/ld: skipping incompatible /usr/local/MATLAB/R2012a_Student/bin/glnx86//libeng.so when searching for -leng
/usr/bin/ld: cannot find -leng
/usr/bin/ld: skipping incompatible /usr/local/MATLAB/R2012a_Student/bin/glnx86//libmat.so when searching for -lmat
/usr/bin/ld: cannot find -lmat
/usr/bin/ld: skipping incompatible /usr/local/MATLAB/R2012a_Student/bin/glnx86//libmex.so when searching for -lmex
/usr/bin/ld: cannot find -lmex
/usr/bin/ld: skipping incompatible /usr/local/MATLAB/R2012a_Student/bin/glnx86//libut.so when searching for -lut
/usr/bin/ld: cannot find -lut
collect2: ld returned 1 exit status

当我使用-m32运行g ++命令时:

g++ -m32 onlineTraining.cpp -I /usr/local/MATLAB/R2012a_Student/extern/include/ -L /home/forest/SoarSuite/out/ -L /usr/local/MATLAB/R2012a_Student/bin/glnx86/ -I /home/forest/SoarSuite/out/include -leng -lmat -lmex -lut -lSoar

我得到以下输出,因为它现在无法识别64位.so文件:

/usr/bin/ld: skipping incompatible /home/forest/SoarSuite/out//libSoar.so when searching for -lSoar
/usr/bin/ld: cannot find -lSoar
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status

是否可以同时链接34位和64位.so文件? 谢谢。

不,这是不可能的。 32位库只能链接到32位可执行文件,而64位库只能链接到64位可执行文件。

如果您尝试链接的Matlab库仅作为32位提供,则需要将应用程序构建为32位(使用-m32 ),并仅链接到32位库。

我建议制作一个shell脚本或make文件来运行两个编译器命令。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM