在c++程序中用g++链接32位和64位.so文件

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

本文关键字:32位 64位 so 文件 链接 g++ c++ 程序      更新时间:2023-10-16

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

当我运行g++命令时:

<>之前g++ onlintraining .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:跳过不兼容的/usr/local/matlab/r2012a_student/bin/glnx86//libeng。所以当搜索- length时/usr/bin/ld:找不到- length/usr/bin/ld:跳过不兼容的/usr/local/matlab/r2012a_student/bin/glnx86//libmat。所以当搜索-lmat时/usr/bin/ld:无法找到-lmat/usr/bin/ld:跳过不兼容的/usr/local/matlab/r2012a_student/bin/glnx86//libmex。所以当搜索-lmex时/usr/bin/ld:找不到-lmex/usr/bin/ld:跳过不兼容的/usr/local/matlab/r2012a_student/bin/glnx86//libut。所以当搜索-lut时/usr/bin/ld:找不到-lutCollect2: ld返回1退出状态之前

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

<>之前g++ -m32 onlintraining .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:跳过不兼容的/home/forest/soarsuite/out//libSoar。所以当搜索-lSoar时/usr/bin/ld:找不到-lSoar/usr/bin/ld:跳过不兼容的/usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++。所以当搜索-lstdc++时/usr/bin/ld:跳过不兼容的/usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++。当搜索-lstdc++时/usr/bin/ld:找不到-lstdc++Collect2: ld返回1退出状态之前

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

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

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

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