本文介绍了如何通过在CentOS 7上创建libcxx和libcxxabi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在CentOS 7上使用clang / clang ++的C ++ 11或C ++ 14.如何构建这个构建环境?

解决方案

本文教会如何在CentOS 7上构建C ++ 11构建环境:RHEL的EPEL repo提供Clang软件包,但没有C ++库软件包。所以,这些部分是有点麻烦由手建造。 Clang的定制C ++库是libc ++(libcxx)[1]。然后,libcxx还需要一个ABI库libc ++ abi(libcxxabi)[2]。不幸的是,这两个库有一个循环依赖的问题。为了打破循环依赖性问题,可以构建libc ++而不链接libc ++ abi。然后,使用这个libc ++,我们可以构建libc ++ abi连接libc ++。最后,使用libc ++ abi,​​我们可以构建一个新的libc ++链接libc ++ abi。



clang,libc ++和libc ++ abi环境构建步骤在下面给出:


  1. 添加RHEL的EPEL仓库。
    打开以下链接,并找到如何使用这些额外的软件包?部分。


    查找您的CentOS版本的epel包。例如:

      sudo rpm -i https://dl.fedoraproject.org/pub/epel/epel-release-latest -7.noarch.rpm 


  2. 安装Subversion获取最新的libcxx和libcxxabi。 p>

      sudo yum install svn 


  3. 安装Clang和llvm-devel(使用llvm-config)。

      sudo yum install clang llvm -devel 


  4. 安装cmake。

      cd / usr / local 
    wget https://cmake.org/files/v3.5/cmake-3.5.2-Linux-i386.sh
    sudo chmod 755 cmake-3.5.2-Linux-i386.sh
    sudo ./cmake-3.5.2-Linux-i386.sh
    #检查cmake是否在/ usr / local / bin中。


  5. 第一轮建立libcxx而不使用libcxxabi。

     #获取libcxx。 
    svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
    cd libcxx
    #不建议在源根目录中构建libcxx。
    #所以,我们做一个tmp目录。
    mkdir tmp
    cd tmp
    #指定要释放的CMAKE_BUILD_TYPE将生成性能优化的代码。
    #CMAKE_INSTALL_PREFIX将安装路径从默认的/ usr / local更改为/ 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 ..


  6. 使用libc ++构建libcxxabi。

     #获取libcxxabi。 
    svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi
    cd libcxxabi
    mkdir tmp
    cd tmp
    cmake -DCMAKE_BUILD_TYPE =发布-DCMAKE_INSTALL_PREFIX = / usr -DCMAKE_C_COMPILER = clang -DCMAKE_CXX_COMPILER = clang ++ -DLIBCXXABI_LIBCXX_INCLUDES = .. / .. / libcxx / include ..
    sudo make install
    cd ../ ..


  7. 第二轮使用libcxxabi构建libcxx。

      CD libcxx 
    的mkdir TMP
    CD TMP
    #这一次,我们要编译libcxx与libcxxabi,所以我们必须指定LIBCXX_CXX_ABI = libcxxabi和路径到libcxxabi标头,LIBCXX_LIBCXXABI_INCLUDE_PATHS。
    cmake的-DCMAKE_BUILD_TYPE =发行-DCMAKE_INSTALL_PREFIX =的/ usr -DCMAKE_C_COMPILER =铛-DCMAKE_CXX_COMPILER =铛++ -DLIBCXX_CXX_ABI = libcxxabi -DLIBCXX_CXX_ABI_INCLUDE_PATHS = .. / .. / libcxxabi /包括..
    须藤使安装


  8. 写C ++测试程序。

      // t.cpp 
    #include< iostream>
    using namespace std;
    int main(){
    cout<< 你好,世界! << endl;
    }


  9. 测试C ++用铿锵++。

    $ B $编译b

     #-std指定C ++标准。 -stdlib指定要与clang / clang ++一起使用的C ++库。 -lc ++ ABI是必要的,因为新的LD(链接器和加载)在CentOS 7不允许间接库链接。 
    ++铿锵-std = C ++ 11 -stdlib = ++的libc -lc ++ ABI t.cpp
    ./a.out




参考:结果
[1]的结果
[2]的


I want to use C++11 or C++14 with clang/clang++ on CentOS 7. How do I build this building environment?

解决方案

This article teaches how to build C++11 building environment on CentOS 7: RHEL's EPEL repo provides Clang packages, but no C++ library packages. So, these parts are a bit troublesome to be built by hand. The customized C++ libraries for Clang is libc++ (libcxx) [1]. Then, libcxx also needs an ABI library, libc++abi (libcxxabi) [2]. Unfortunately, these two libraries have a circular dependency problem. For breaking the circular dependency problem, libc++ can be built without linking libc++abi. Then, with this libc++, we can build libc++abi linking libc++. Finally, with the libc++abi, we can build a new libc++ linking libc++abi.

The clang, libc++, and libc++abi environment building steps are given in the following:

  1. Add RHEL's EPEL repo.Open the following link and find the section "How can I use these extra packages?"https://fedoraproject.org/wiki/EPEL
    Find the epel package for your CentOS version. E.g.,:

    sudo rpm -i https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    

  2. Install Subversion for getting the latest libcxx and libcxxabi.

    sudo yum install svn
    

  3. Install Clang and llvm-devel (with llvm-config).

    sudo yum install clang llvm-devel
    

  4. Install cmake.

    cd /usr/local
    wget https://cmake.org/files/v3.5/cmake-3.5.2-Linux-i386.sh
    sudo chmod 755 cmake-3.5.2-Linux-i386.sh
    sudo ./cmake-3.5.2-Linux-i386.sh
    # Check cmake is in /usr/local/bin.
    

  5. 1st round to build libcxx without libcxxabi.

    # Get libcxx.
    svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
    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 ..
    

  6. Build libcxxabi with libc++.

    # Get libcxxabi.
    svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi
    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 ../..
    

  7. 2nd round to build libcxx with libcxxabi.

    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
    

  8. Write a C++ test program.

    // t.cpp
    #include <iostream>
    using namespace std;
    int main() {
      cout << "Hello world!" << endl;
    }
    

  9. Test C++ compilation by clang++.

    # -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/

这篇关于如何通过在CentOS 7上创建libcxx和libcxxabi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 09:35