2016-05-27 67 views
0

我在我的OpenSUSE上發佈了一段C++軟件,我喜歡在另一個OpenSUSE系統上進行測試。如何通過g ++編譯獨立的可執行文件?

我複製了其他系統上的可執行文件,但是當我開始它,我收到一個錯誤:

"error while loading shared libraries: libboost_system.so.1.61.0: cannot open shared object file: No such file or directory"

我怎麼能編譯不依賴一個獨立的可執行文件?

Eclipse一樣,這樣的:

17:24:41 **** Incremental Build of configuration Debug for project boostServer **** 
make all 
Building file: ../src/boostCom.cpp 
Invoking: Cross G++ Compiler 
g++ -I/opt/boost -I/usr/local/lib -O0 -g3 -Wall -c -fmessage-length=0 -isystem /opt/boost -MMD -MP -MF"src/boostCom.d" -MT"src/boostCom.o" -o "src/boostCom.o" "../src/boostCom.cpp" 
Finished building: ../src/boostCom.cpp 

Building file: ../src/main.cpp 
Invoking: Cross G++ Compiler 
g++ -I/opt/boost -I/usr/local/lib -O0 -g3 -Wall -c -fmessage-length=0 -isystem /opt/boost -MMD -MP -MF"src/main.d" -MT"src/main.o" -o "src/main.o" "../src/main.cpp" 
Finished building: ../src/main.cpp 

Building target: boostServer 
Invoking: Cross G++ Linker 
g++ -L/usr/local/lib -o "boostServer" ./src/boostCom.o ./src/boostServer.o ./src/main.o -lboost_system -lboost_serialization -lboost_thread -lboost_date_time -lpthread 
Finished building target: boostServer 

電賀烏爾夫

+0

您可能會使用靜態鏈接。 –

+0

@Ulf在鏈接g ++中使用'-static'。 (即列表中的最後一個),那麼,如果有靜態庫,它會優先選擇opon共享的。 – SHR

回答

0

你需要確保你有在系統上安裝Boost庫,這給他們的路徑被包含在你LD_LIBRARY_PATH變量。

例如,如果在您的系統上找到libboost_system.so文件(或符號鏈接)/usr/local/boost-1.56.0/lib64,那麼您將運行該命令。

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/boost-1.56.0/lib64` 

要找出到底哪些庫需要,可以運行命令:

ldd my_binary 

輸出將確切地告訴你所需要的庫,和那些目前無法得到解決。

+0

我是否需要在其他系統上始終安裝所有使用的庫?我不能將它包含在可執行文件中嗎? – Ulf

+0

不,不是全部 - 只是您嘗試運行的二進制文件需要的文件。我已經更新了我的答案,以顯示如何完成這項工作 – Smeeheey

+0

好吧,如果我通過mingw爲Windows機器交叉編譯,這將如何工作? * .exe文件應包含所有內容。 – Ulf

相關問題