我正在尝试为 C++ 程序同时链接 32 位和 64 位 .so 文件。 我正在使用 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 位库。
关于c++ - 将 32 位和 64 位 .so 文件与 g++ 链接为 c++ 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14271014/