2013-01-11 46 views
3

我想同時鏈接32位和64位.so文件在一個c + +程序。 我正在使用64位Ubuntu 12.04.1我也沒有重新編譯的源文件。鏈接32位和64位.so文件與g ++爲一個c + +程序

當我運行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 

當我運行的G ++與命令 - m32:

 
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文件? 謝謝。

+0

你爲什麼要這樣做? – user93353

+0

@ user93353我正在使用C++程序來連接Matlab和稱爲SOAR的認知架構。我沒有選擇在我的電腦上這樣做,因爲我只有32位的二進制文件和SOAR的64位二進制文​​件,我沒有源文件來重新編譯它們。 – user1968703

回答

2

不,這是不可能的。只能將32位庫鏈接到32位可執行文件中,並且只能將64位庫鏈接到64位可執行文件中。

如果您嘗試鏈接的Matlab庫僅提供32位,則需要將應用程序構建爲32位(使用-m32),並且僅鏈接到32位庫中。

+0

好的,我很害怕這個。感謝您及時的回覆。 – user1968703

-1

我建議製作一個shell腳本或運行這兩個編譯器命令的make文件。

+0

這甚至不開始解決問題... – us2012

+0

@ us2012爲什麼不呢? –

+0

問題描述爲「嘗試鏈接爲32位失敗並嘗試鏈接爲64位失敗」,則建議的解決方案是「同時執行」。這有什麼幫助? – us2012