在Ubuntu上安装libc ++ [英] Install libc++ on ubuntu

查看:494
本文介绍了在Ubuntu上安装libc ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在Ubuntu上安装二进制libc ++的正确/简便方法是什么,例如我的Trusty aka 14.04?

I am wondering what is the right/easy way to install a binary libc++ on Ubuntu, in my case Trusty aka 14.04?

在LLVM网站上有apt软件包 http://apt.llvm.org/ ,我已经使用它们安装了3.9。但是,这些软件包似乎并不包含libc ++。我安装了libc ++-dev软件包,但这似乎是一个很旧的版本。也可以下载二进制文件 http://llvm.org/releases/download.html #3.9.0 。它们似乎确实包含libc ++,但是我不确定是否可以将其复制到/ usr / include / c ++ / v1之类的地方,实际上我不确定要复制哪些位。我知道我可以从此处记录的替代位置使用libc ++ http://libcxx.llvm.org我尝试过的/docs/UsingLibcxx.html 。但是,我无法修改要进行此工作的大型代码库的构建系统。

On the LLVM web site there are apt packages http://apt.llvm.org/ and I have used these to install 3.9. However these packages don't seem to include libc++. I install the libc++-dev package but that seems to be a really old version. There are also binaries that can be downloaded http://llvm.org/releases/download.html#3.9.0. These do seem to contain libc++ but I'm not sure if I can just copy bits of this into places like /usr/include/c++/v1, in fact I'm not really sure what bits I would need to copy. I am aware I can use libc++ from an alternate location as documented here http://libcxx.llvm.org/docs/UsingLibcxx.html which I have tried. However I can't modify the build system of the large code base I work on to do this.

所以apt软件包不包含libc ++和

So is three any reason the apt packages don't include libc++ and any pointers to installing a binary would be gratefully recieved.

推荐答案

如何在Ubuntu 16.04上构建libc ++



我遇到了与您类似的问题。虽然使用libstdc ++测试clang可以在C ++ 11和C ++ 14上正常运行,但libstdc ++可能仍然存在许可问题。因此,我最终从他们的存储库中安装了Clang工具链,并在Ubuntu 16.04上编译了libc ++。

How to build libc++ on Ubuntu 16.04

I had a similar issue as you do. While testing clang with libstdc++ worked fine with C++11 and C++14 there still might be licensing issues with libstdc++. So I ended up installing Clang toolchain from their repos and compiling libc++ on Ubuntu 16.04.

免责声明:在Ubuntu Linux上构建 libc ++ 。我在2017年发现的许多帖子要么已经过时,要么描述了其他系统的部分解决方案,例如CentOS的。这些帖子的链接是:

Disclaimer: This post is summary of long search on how to build the libc++ on Ubuntu Linux. Many of the posts I found in 2017 were either outdated or described a partial solution on other systems e.g. CentOS. Links to these posts are:

  • Hacking with Clang llvm abi and llvm libc
  • Building Clang and libc++ on Ubuntu Linux
  • How to Build libcxx and libcxxabi by clang on CentOS 7

以下是从4.0版本分支构建LLVM + Clang + libc ++的步骤:

Here are the steps to build LLVM + Clang + libc++ from the 4.0 release branch:


  1. 安装LLVM存储库的密钥

  1. Install the key of LLVM Repositories

#apt-get update& ;&易于获取dist-upgrade -y&& apt-get install -y vim curl&& \
curl -q https://apt.llvm.org/llvm -snapshot.gpg.key | apt键添加-

# apt-get update && apt-get dist-upgrade -y && apt-get install -y vim curl && \ curl -q https://apt.llvm.org/llvm-snapshot.gpg.key |apt-key add -

创建新的新APT存储库文件(您也可以排除2个引用v3.9存储库的行)

Create a new new APT Repository File (you can also exclude 2 lines referring to v3.9 repos)

#cat> /etc/apt/sources.list.d/llvm-repos.list<< EOF
deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial main
deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial main
deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-3.9 main
deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-3.9 main
deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-4.0 main
deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-4.0 main
EOF

# cat > /etc/apt/sources.list.d/llvm-repos.list <<EOF deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial main deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial main deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-3.9 main deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-3.9 main deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-4.0 main deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-4.0 main EOF

安装Clang和从LLVM存储库构建libc ++所需的所有软件包

Install Clang and all Packages needed to build libc++ from LLVM repos

#apt-get update&& apt-get install -y clang-4.0 clang-4.0-doc \
libclang-common-4.0-dev libclang-4.0-dev libclang1-4.0 libclang1-4.0-dbg \
libllvm4.0 libllvm4 .0-dbg lldb-4.0 llvm-4.0 llvm-4.0-dev llvm-4.0-runtime \
clang-format-4.0 python-clang-4.0 liblldb-4.0-dev lld-4.0 libfuzzer-4.0-dev \ \
颠覆cmake

为C ++编译器和链接器创建替代项。这不是必须的,但可以根据需要切换编译器或链接器。另外,一些构建文件需要 cc c ++ clang ++ 作为据我所记得。请记住,我们默认切换到LLD链接器:

Create an alternative for C++ compiler and linker. This is not a must, but lets you switch compilers or linkers if needed. Also some build files needed cc or c++ or clang++ as far as I remember. Keep in mind, that we switch to LLD linker as default:

update-alternatives --install / usr / bin / cc cc / usr / bin / clang-4.0 100 \
&& update-alternatives --install / usr / bin / c ++ c ++ /usr/bin/clang++-4.0 100 \
&& update-alternatives --install / usr / bin / clang ++ clang ++ /usr/bin/clang++-4.0 100 \
&& update-alternatives --install / usr / bin / clang clang /usr/bin/clang-4.0 100 \
&& update-alternatives --install / usr / bin / ld ld /usr/bin/ld.lld-4.0 10 \
&& update-alternatives --install / usr / bin / ld ld /usr/bin/ld.gold 20 \
&& update-alternatives --install / usr / bin / ld ld /usr/bin/ld.bfd 30 \
&& ld-版本&&回声3 | update-alternatives --config ld&& ld --version

检出 libc ++ 和<$ c的源$ c> libc ++ abi :

$ cd / tmp
$ svn co <​​a href = http://llvm.org/svn/llvm-project/libcxx/branches/release_40/ rel = nofollow noreferrer> http://llvm.org/svn/llvm-project/libcxx/branches/release_40/ libcxx
$ svn co <​​a href=\"http://llvm.org/svn/llvm-project/libcxxabi/branches/release_40/\" rel=\"nofollow noreferrer\"> http:// llvm .org / svn / llvm-project / libcxxabi / branches / release_40 / libcxxabi
$ mkdir -p libcxx / build libcxxabi / build

$ cd /tmp $ svn co http://llvm.org/svn/llvm-project/libcxx/branches/release_40/ libcxx $ svn co http://llvm.org/svn/llvm-project/libcxxabi/branches/release_40/ libcxxabi $ mkdir -p libcxx/build libcxxabi/build

要在Linux上运行 libc ++ ,需要ABI与标准库的兼容性,例如libstdc ++。这就是 libc ++ abi 进入游戏的地方。唯一的问题是,它需要 libc ++ 才能在要为其构建系统的系统上使用。因此,分两个步骤构建 libc ++ 。第一:没有任何ABI兼容性。但是它将用于引导ABI lib,第二步是使用系统上存在的正确ABI重新编译 libc ++

To run libc++ on Linux one needs ABI compatibility to the standard library, e.g. libstdc++. This is where libc++abi comes into game. The only problem is that it needs libc++ to be on the system for which it is build. Thus libc++ is built in 2 steps. First: without any ABI compatibility. But it will be used for bootstrapping of ABI lib and than the second step is to recompile libc++ with the proper ABI present on system:

Bootstraping =>在没有适当ABI的情况下构建 libc ++

Bootstraping => build libc++ without proper ABI:

cd / tmp / libcxx / build
cmake -DCMAKE_BUILD_TYPE =发布-DLLVM_CONFIG_PATH = / usr / bin / llvm-config-4.0\
-DCMAKE_INSTALL_PREFIX = / usr ..\
&&进行安装

使用<$ c构建 libc ++ abi $ c> libstdc ++ 兼容的ABI:

Building libc++abi with libstdc++ compatible ABI:

cd / tmp / libcxxabi / build
CPP_INCLUDE_PATHS = echo | c ++ -Wp,-v -x c ++--fsyntax-only 2>& 1 \
| grep'/ usr'| tr'\n'''| tr -s''| tr'' ';'

CPP_INCLUDE_PATHS = / usr / include / c ++ / v1 /; $ CPP_INCLUDE_PATHS
cmake -G Unix Makefiles -DLIBCXX_CXX_ABI = libstdc ++ \
-DLIBCXX_LIBSUPCXX_INCLUDE_PATHS = $ CPP_INCLUDE_PATHS \
-DCMAKE_BUILD_TYPE =发行版-DCMAKE_INSTALL_PREFIX = / usr \
-DLLVM_CONFIG_PATH = / usr / bin / llvm-config-4.0D bBC $ LILI = .. / .. / libcxx / include ..
进行安装

重建 libc ++ 并在系统上部署了适当的ABI库:

Rebuild libc++ with proper ABI lib deployed on system:

cd / tmp / libcxx / build
cmake -DCMAKE_BUILD_TYPE =发布-DCMAKE_INSTALL_PREFIX = / usr \
-DLIBCXX_CXX_ABI = libcxxabi -DLLVM_CONFIG_PATH = / usr / bin / llvm-config-4.0\
-DLIBCXX_CXX_AXX_ABI_INCLUDE_PATHS = .. / .. / libcxxabi / include ..
&&进行安装

创建测试文件以检查一切是否正常。 IMO,您还应该测试 cerr 流,因为以前 libc ++ abi 不支持它。段错误。请参阅此问题

Create a test file to check whether everything works fine. IMO you should also test cerr stream, as previously it was not supported with the libc++abi and there were some segfaults. Please refer to this question.

创建一个test.cpp文件:

create a test.cpp file:

#include< iostream>
int main()
{
使用命名空间std;
cout<< [OK]世界您好! <<恩德尔
cerr<< [OK]大家好! <<恩德尔
堵塞<< [确定]世界您好! <<恩德尔
返回0;
}

并使用以下命令行对其进行编译和运行:

And compile it and run it using this command line:

clang ++ -std = c ++ 11 -stdlib = libc ++ -lc ++ abi test.cpp& ./a.out



原因是没有包裹



我找到了Ubuntu的libc ++软件包,但是它们比最新版本落后一些: https://packages.ubuntu.com/xenial/libc++-dev

为什么它们不是最新的,我无法回答,但是我的猜测是L​​LVM + Clang几乎可以与任何标准库一起使用,而您所看到的libc ++必须链接到特定的运行时ABI,并且可能在很大程度上取决于可用的C运行时库。我同意应该有一个涵盖90%案例的软件包。可能这仅仅是缺乏资源。 搜索邮件归档文件没有显示任何特殊内容。

Why they are not current, I can't answer, but my guess is that LLVM+Clang can work with mostly any Standard Library, whereas libc++ as you see must be linked to particular runtime ABI and might heavily depend on available C runtime library. I agree there should be a package which covers 90% of the cases. May be this is just the lack of resources. Searching the mailing archive did not bring up anything special.

这篇关于在Ubuntu上安装libc ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆