我們手動科學的Linux機器上安裝了GCC 6.2.0未定義的引用。一個C++應用程序的編譯似乎不錯,但我們在鏈接時CXX11與GCC 6.2.0
file.cpp:(.text+0x16cb): undefined reference to `std::__cxx11::list<void*, std::allocator<void*> >::list(std::__cxx11::list<void*, std::allocator<void*> > const&)'
獲得大量的undefined references
到CXX11我們意識到double ABI issue,但與-D_GLIBCXX_USE_CXX11_ABI=0
編譯沒什麼區別。我們還有什麼其他選擇?
UPDATE
CMake的配置是如下:
-- The C compiler identification is GNU 6.2.0
-- The CXX compiler identification is GNU 6.2.0
-- Check for working C compiler: /opt/GNU/gcc-6.2.0/bin/gcc
-- Check for working C compiler: /opt/GNU/gcc-6.2.0/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /opt/GNU/gcc-6.2.0/bin/g++
-- Check for working CXX compiler: /opt/GNU/gcc-6.2.0/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
這是file.cpp
gcc-6.2.0/bin/g++ -O3 -fopenmp -DNO_HDF5 -D_GLIBCXX_USE_CXX11_ABI=0 -I./include -I/opt/mpich/3.2/include -o file.cpp.o -c file.cpp
和鏈接(其中它實際上失敗)
編譯行gcc-6.2.0/bin/g++ -O3 -fopenmp -DNO_HDF5 -D_GLIBCXX_USE_CXX11_ABI=0 main.cpp.o -o ASTEP -rdynamic libMainASTEPlib.a -lhdf5_hl -lhdf5 -lz -lm -lhdf5_hl -lhdf5 -lz -lm /opt/mpich/3.2/lib/libmpicxx.so /opt/mpich/3.2/lib/libmpi.so -Wl,-rpath,/opt/mpich/3.2/lib
此外,MPICH 3.2已建成新的編譯器(GCC 6.2.0)
*您如何鏈接您的程序?用'ld'?用'gcc'?用'g ++'? –
刪除目標文件並重新編譯。 –
在安裝gcc時,gcc更願意假設它的庫將被安裝到/ usr/lib(64)?中,而不管你真的在哪裏推送gcc。因此,您的代碼最終會與系統的標準庫鏈接。不幸的是,我忘記了如何從gcc的配置中剔除糟糕的細節,以便正確設置它以便與安裝它們的庫鏈接。你必須弄清楚,就像我在10年前做的那樣......如果我記得所有這些,我會發佈一個答案。 –