What is the sanctioned way to build libc++ for clang on Linux?

Asked
Active3 hr before
Viewed126 times

6 Answers

build
90%

Thanks for contributing an answer to Stack Overflow!, Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers , 1 This no longer works (with SVN libc++). With the resulting libc++.so, any attempt to compile with -std=c++0x -stdlib=libc++ results in a mysterious undefined reference to `vtable for std::nested_exception' – Steven Lu Nov 25 '13 at 22:30 ,The libc++ website has a nice overview of the possible ways to build libc++.

Also see the Arch Linux User Repository build script, which uses the buildit script. I installed libc++ from that and used it with the Arch Linux Clang package succesfully by using

clang++ - std = c++11 - stdlib = libc++ - lc++abi
88%

This buildit script appears to not make use of libsupc++ which is what the cmake approach that I took earlier used. For instance, this guide shows one cmake incantation to produce a makefile for libc++, which will be able to take care of compiling and installation. ,The buildit script does not appear to provide any help for installation. Are there directions anywhere for how to properly install the library? With my previous libc++ built with cmake, I had to always add -lc++ to the linker flags (and the path with -L), which is not necessary in my OS X makefiles.,Also see the Arch Linux User Repository build script, which uses the buildit script. I installed libc++ from that and used it with the Arch Linux Clang package succesfully by using,In the past I have been able to succeed by doing something with cmake, but just now I discovered a buildit script inside the lib directory of the http://llvm.org/svn/llvm-project/libcxx/trunk project tree.

Also see the Arch Linux User Repository build script, which uses the buildit script. I installed libc++ from that and used it with the Arch Linux Clang package succesfully by using

clang++ - std = c++11 - stdlib = libc++ - lc++abi
72%

Using Alternate ABI libraries Using libsupc++ on Linux Using libcxxrt on Linux ,Using libsupc++ on Linux,Using libcxxrt on Linux,The default way of building libc++, libc++abi and libunwind is to root the CMake invocation at <monorepo>/runtimes. While those projects are under the LLVM umbrella, they are different in nature from other build tools, so it makes sense to treat them as a separate set of entities. The default build can be achieved with the following CMake invocation:

$ git clone https: //github.com/llvm/llvm-project.git
   $ cd llvm - project
$ mkdir build
$ cmake - G Ninja - S runtimes - B build - DLLVM_ENABLE_RUNTIMES = "libcxx;libcxxabi;libunwind"
# Configure
$ ninja - C build cxx cxxabi unwind # Build
$ ninja - C build check - cxx check - cxxabi check - unwind # Test
$ ninja - C build install - cxx install - cxxabi install - unwind # Install
load more v
65%

Anything older than these toolchains may work, but will require forcing the build system with a special option and is not really a supported host platform. Also note that older versions of these compilers have often crashed or miscompiled LLVM.,LLVM is written using the subset of C++ documented in coding standards. To enforce this language version, we check the most popular host toolchains for specific minimum versions in our build systems:,Note that using clang to compile directly to native code (i.e. when the -emit-llvm option is not present) does steps 6/7/8 for you.,However, using the “Arcanist” tool is often easier. After installing arcanist, you will also need to apply a fix to your arcanist repo in order to submit a patch:

% gcc_version = 5.1 .0 %
   wget https: //ftp.gnu.org/gnu/gcc/gcc-${gcc_version}/gcc-${gcc_version}.tar.bz2
   %
   wget https: //ftp.gnu.org/gnu/gcc/gcc-${gcc_version}/gcc-${gcc_version}.tar.bz2.sig
   %
   wget https: //ftp.gnu.org/gnu/gnu-keyring.gpg
   %
   signature_invalid = `gpg --verify --no-default-keyring --keyring ./gnu-keyring.gpg gcc-${gcc_version}.tar.bz2.sig` %
   if [$signature_invalid];
then echo "Invalid signature";
exit 1;
fi
   %
   tar - xvjf gcc - $ {
      gcc_version
   }.tar.bz2 %
   cd gcc - $ {
      gcc_version
   } %
   . / contrib / download_prerequisites %
   cd.. %
   mkdir gcc - $ {
      gcc_version
   } - build %
   cd gcc - $ {
      gcc_version
   } - build %
   $PWD / .. / gcc - $ {
      gcc_version
   }
/configure --prefix=$HOME/toolchains--enable - languages = c, c++
   %
   make - j$(nproc) %
   make install
load more v
75%

The instructions are for building libc++ on FreeBSD, Linux, or Mac using libc++abi as the C++ ABI library. On Linux, it is also possible to use libsupc++ or libcxxrt.,On Mac OS 10.7 (Lion) and later, the easiest way to get this library is to install Xcode 4.2 or later. However if you want to install tip-of-trunk from here (getting the bleeding edge), read on.,The following options allow building libc++ for a different ABI version.,The C++ compiler to use when building and testing libc++.

$ git clone https: //github.com/llvm/llvm-project.git
   $ cd llvm - project
$ mkdir build && cd build
$ cmake - DCMAKE_C_COMPILER = clang\ -
   DCMAKE_CXX_COMPILER = clang++\
   - DLLVM_ENABLE_PROJECTS = "libcxx;libcxxabi"\.. / llvm
$ make # Build
$ make check - cxx # Test
$ make install - cxx install - cxxabi # Install
load more v
40%

Clang is also provided in all major BSD or GNU/Linux distributions as part of their respective packaging systems. From Xcode 4.2, Clang is the default compiler for Mac OS X.,If you would like to check out and build Clang, the current procedure is as follows:,Note: Some Clang tests are sensitive to the line endings. Ensure that checking out the files does not convert LF line endings to CR+LF. If you're using git on Windows, make sure your core.autocrlf setting is false.,Note: For subsequent Clang development, you can just run make clang.

The clang tool is the compiler driver and front-end, which is designed to be a drop-in replacement for the gcc command. Here are some examples of how to use the high-level driver:

$ cat t.c
#include <stdio.h>
int main(int argc, char **argv) { printf("hello world\n"); }
$ clang t.c
$ ./a.out
hello world
load more v

Other "build-undefined" queries related to "What is the sanctioned way to build libc++ for clang on Linux?"