Gcc
如何指定要使用的 libstdc++.so.6
我正在嘗試編譯我的程序,它需要
C++11
功能和boost
比目標機器上安裝的更新版本。因此,我使用所有依賴項和 binutils 的樹內建構編譯並安裝gcc 4.9
到某個本地目錄 ( )。/secured/local
然後我下載boost 1.55
並執行./boostrap.sh --prefix=/secured/local && ./b4 install
安裝boost。兩種編譯都執行良好,gcc -std=c++11
也可以正常工作。我的程序是使用 cmake 建構的,
FindXX.cmake
具有查找文件的通常過程。我正在像這樣執行cmake:cmake ../source/ -DBOOST_ROOT=/secured/local -DCMAKE_EXE_LINKER_FLAGS='-Wl,-rpath,/secured/local/lib'
它成功地找到了我的新 boost 安裝和新版本的 gcc。編譯和連結都可以完美地工作。但是,在執行我的程序時,我收到以下錯誤:
$ ./surface ./surface: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by ./surface) ./surface: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by ./surface) ./surface: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by ./surface) ./surface: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.19' not found (required by ./surface) ./surface: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /secured/local/lib/libconfig++.so.9) ./surface: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /secured/local/lib/libboost_program_options.so.1.55.0) ./surface: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by /secured/local/lib/libboost_program_options.so.1.55.0) ./surface: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /secured/local/lib/libboost_program_options.so.1.55.0) ./surface: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /secured/local/lib/libboost_filesystem.so.1.55.0) ./surface: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /secured/local/lib/libboost_regex.so.1.55.0) ./surface: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by /secured/local/lib/libboost_regex.so.1.55.0) ./surface: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /secured/local/lib/libboost_regex.so.1.55.0) ./surface: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by /secured/local/lib/libboost_regex.so.1.55.0)
objdump
在助推節目上執行objdump -x /secured/local/lib/libboost_program_options.so.1.55.0 | grep stdc++ NEEDED libstdc++.so.6 required from libstdc++.so.6:
似乎兩個 boost 庫都嘗試使用舊的
/usr/lib64/libstdc++.so.6
而不是/secured/local/lib
. 我在程序中做錯了什麼?請注意,我盡量避免設置
LD_LIBRARY_PATH
某處。
安裝
gcc
將 alibstdc++.so.6
放入$PREXIF/lib
和$PREFIX/lib64
中。使用後者作為RPATH
提升,我的程序解決了這個問題。僅使用前者會導致回退到系統libstdc++.so.6
。