Clang与libc++abi库安装

时间:2022-07-14 16:21:33

系统ubuntu64位 Clang4.0

参考:

1 https://github.com/yangyangwithgnu/use_vim_as_ide#0.1

  其中 第7章 工具链集成

2. http://clang.llvm.org/get_started.html

  其中 Release Clang Versions

3. http://libcxxabi.llvm.org/

  其中 Get it and get involved!

先开始进行按照1中的方式单独编译 Clang/llvm以及相应的库,在单独编译 libcxx以及libcxxabi库,其中libcxxabi 编译时报错 :clang-4.0 link error

3中提出libcxx以及libcxxabi库可以集成或单独编译,于是在2中直接将libcxxabi库直接包含在llvm/projects里面,最后集成编译整个项目。

最后用Clang++ 编译后一下文件。

编译源文件如下:

//new_feature.cpp
#include <iostream>
#include <string> class MyClass
{
public:
std::string s ="Hello, world\n"; // Non-static data member initializer
}; int main()
{
std::cout << MyClass().s;
}

编译命令如下

clang++ -std=c++11 -stdlib=libc++ -Werror -Weverything -Wno-disabled-macro-expansion -Wno-float-equal -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-global-constructors -Wno-exit-time-destructors -Wno-missing-prototypes -Wno-padded -Wno-old-style-cast -lc++ -lc++abi new_feature.cpp

得出的a.out文件出现

./a.out: error while loading shared libraries: libc++abi.so.1: cannot open shared object file: No such file or directory

最后在编译文件里面将一下几个库添加至/usr/lib 里面后得出输出。

库文件分别是:

libc++abi.so libc++abi.so.1 libc++abi.so.1.0
libc++.so.1 libc++.so.1.0 libc++.so

注意:可能需要将 build后生成的include里面的头文件手动拷贝到 /usr/include/c++/v1/ 里面,为了libc++以及libc++abi 的头文件在查找目录。

具体的命令如下:

  1. Get the required tools.
  2. Check out LLVM:
    • Change directory to where you want the llvm directory placed.
    • svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
  3. Check out Clang:
    • cd llvm/tools
    • svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
    • cd ../..
  4. Check out extra Clang tools: (optional)
    • cd llvm/tools/clang/tools
    • svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra
    • cd ../../../..
  5. Check out Compiler-RT (optional):
    • cd llvm/projects
    • svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
    • cd ../..
  6. Check out libcxx: (only required to build and run Compiler-RT tests on OS X, optional otherwise)
    • cd llvm/projects
    • svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
    • svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi
    • cd ../..
  7. Build LLVM and Clang:
    • mkdir build (in-tree build is not supported)
    • cd build
    • cmake -G "Unix Makefiles" ../llvm
    • make
    • This builds both LLVM and Clang for debug mode.
    • Note: For subsequent Clang development, you can just run make clang.
    • CMake allows you to generate project files for several IDEs: Xcode, Eclipse CDT4, CodeBlocks, Qt-Creator (use the CodeBlocks generator), KDevelop3. For more details see Building LLVM with CMake page.