簡體   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