Cent OS 7編譯安裝libc++和libc++abi
本文介紹了如何在CentOS 7中構建C++11構建環境
Clang的定制C++庫是libc++(libcxx)。然後,libcxx還需要一個ABI庫,libc++abi(libcxxabi)。不幸的是,這兩個庫有一個循環依賴問題。為了打破循環依賴問題,可以在不連接libc++abi的情況下構建libc++。然後,使用這個libc++,我們可以構建libc++abi鏈接到libc++。最後,使用libc++abi,我們可以構建一個新的libc++鏈接到libc++abi。
cmake和clang/llvm安裝請見
http://www.cnblogs.com/BinBinStory/p/7461345.html
http://www.cnblogs.com/BinBinStory/p/7499527.html
libc++,libc++abi 構建步驟如下:
1. 獲取libc++,libc++abi
- libc++ source code(.sig)
- libc++abi source code(.sig)
2. 下載好了以後,兩個都解壓出來,得到兩個目錄:
libcxx-4.0.1.src
libcxxabi-4.0.1.src
3. 第一輪構建libcxx,不需要libcxxabi參與。
cd libcxx # It is not recommended to build libcxxin the source root directory. # So, we make a tmp directory. mkdir tmp cd tmp # Specifying CMAKE_BUILD_TYPE to Release shall generate performance optimized code. # The CMAKE_INSTALL_PREFIX changes the install path from the default /usr/local to /usr. cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ..sudo make install cd .. rm tmp -rf cd ..
4. 構建libcxxabi libc++。
cd libcxxabi mkdir tmp cd tmp cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLIBCXXABI_LIBCXX_INCLUDES=../../libcxx/include .. sudo make install cd ../..
5. 第2輪使用libcxxabi構建libcxx。
cd libcxx mkdir tmp cd tmp # This time, we want to compile libcxx with libcxxabi, so we have to specify LIBCXX_CXX_ABI=libcxxabi and the path to libcxxabi headers, LIBCXX_LIBCXXABI_INCLUDE_PATHS. cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLIBCXX_CXX_ABI=libcxxabi -DLIBCXX_CXX_ABI_INCLUDE_PATHS=../../libcxxabi/include .. sudo make install
6. 編寫一個C++測試程序。
// t.cpp #include <iostream> using namespace std; int main() { cout << "Hello world!" << endl; }
7. 通過clang++測試C++編譯。
# -std specifies the C++ standard. -stdlib specifies the C++ library you want to use with clang/clang++. -lc++abi is necessary, because the new LD (linker and loader) on CentOS 7 doesn‘t allow indirect library linking. clang++ -std=c++11 -stdlib=libc++ -lc++abi t.cpp ./a.out
References:
[1] http://libcxx.llvm.org/
[2] http://libcxxabi.llvm.org/
翻譯自:https://stackoverflow.com/questions/25840088/how-to-build-libcxx-and-libcxxabi-by-clang-on-centos-7
Cent OS 7編譯安裝libc++和libc++abi