Gcc

如何指定要使用的 libstdc++.so.6

  • June 4, 2014

我正在嘗試編譯我的程序,它需要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

引用自:https://unix.stackexchange.com/questions/134266