CentOS7編譯安裝libc++和libc++abi

本文介紹瞭如何在CentOS 7中構建C++11構建環境html

Clang的定製C++庫是libc++(libcxx)。而後,libcxx還須要一個ABI庫,libc++abi(libcxxabi)。不幸的是,這兩個庫有一個循環依賴問題。爲了打破循環依賴問題,能夠在不鏈接libc++abi的狀況下構建libc++。而後,使用這個libc++,咱們能夠構建libc++abi連接到libc++。最後,使用libc++abi,咱們能夠構建一個新的libc++連接到libc++abi。ios

cmake和clang/llvm安裝請見c++

http://www.cnblogs.com/BinBinStory/p/7461345.htmlcentos

http://www.cnblogs.com/BinBinStory/p/7499527.html測試

libc++,libc++abi 構建步驟以下:ui

1. 獲取libc++,libc++abi spa

2. 下載好了之後,兩個都解壓出來,獲得兩個目錄:翻譯

  libcxx-4.0.1.srccode

  libcxxabi-4.0.1.srcorm

3. 第一輪構建libcxx,不須要libcxxabi參與。

cd libcxx
# It is not recommended to build libcxx in 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

相關文章
相關標籤/搜索