CentOS 6.4 Compile and install Llvm3.3,clang and libc++

Source: Internet
Author: User

Originally the latest version is already 3.4, but, before the compilation once, failed, so this time first use 3.3

In addition this is reproduced the article

Http://www.cnblogs.com/codemood/p/3142848.html

?

LLVM's latest version of 3.3 finally released on June 17, according to the previous plan June 5 should be released, but it is not too late to catch up with VS2013 preview (June 26 Microsoft Build conference) came out. Plus before gcc4.8.1 at the end of May June, today's top three C + + compilers are releasing important updates this month, and this June is a good day for C + +!

LLVM has been announced before the c++11 Feature complete, 3.3 should be the first stable version, before gcc4.8.1 is also full support c++11, this article describes how to compile on CentOS install the latest Gcc,vs has been a lot behind , but is still looking forward to VS2013 preview to increase the number of c++11 features.

LLVM3.3 offers a very rich pre-built Binaries including ubuntu13.04,ubuntu12.04 and Ubuntu10.04, as well as Debian6, FreeBSD9 and Fedora18, And, of course, Apple's own Mac OS X. Unfortunately, there is no pre-compiled version for CentOS, it can only be compiled and installed by itself.

Today, the latest version of the LLVM kit (Llvm,clang and libc++) is installed on CentOS, and there are a lot of problems in the middle. Although there are many blogs about how to compile and install LLVM, but according to my own experience of the situation, there is a place to pay attention to, there is something worth sharing with you.

The installation process mainly refers to these articles:

Http://clang.llvm.org/get_started.html

Http://www.cnblogs.com/Frandy/archive/2012/10/20/llvm_clang_libcxx_cxx11.html

Http://www.cnblogs.com/ralphjzhang/archive/2011/12/02/2272671.html

Start here:

First, download the latest version from the http://llvm.org/releases/download.html#3.3 side. If you download the code from SVN, it is already a 3.4 development version, if you need to use a stable version, it is recommended to download 3.3 of the code package, you need to download 5 files:

LLVM Source Code

Clang Source Code

Clang Tools Extra Source code

Compiler RT Source Code

Libc++ Source Code

After the download, four compressed packets are extracted, get four directories:

Llvm-3.3.src

Cfe-3.3.src

Clang-tools-extra-3.3.src

Compiler-rt-3.3.src

Libcxx-3.3.src

Then follow these steps to organize:

mv cfe-3.3.src clang

mv clang/ llvm-3.3.src/tools/

?

mv clang-tools-extra-3.3.src extra

mv extra/ llvm-3.3.src/tools/clang/

?

mv compiler-rt-3.3.src compiler-rt

mv compiler-rt llvm-3.3.src/projects/

In this way Clang,clang-tools-extra and COMPILER-RT can be compiled together with LLVM.

Create a new directory on the LLVM-3.3.SRC same level directory build-3.3 and enter:

mkdir build-3.3

cd build-3.3

Then configure:

../llvm-3.3.src/configure --enable-optimized --enable-targets=host-only

Note : Here are two options recommended to add , otherwise it will produce huge files, when I first compile, did not add these two options, compiled the result of how big 9.4G(scary?) My disk is exhausted, also reported wrong, Google for a long time to find that the disk space is not enough), takemore than 1.5 hours, plus the results compiled later than the 1g,i5 four core 20 minutes more than the compilation completed.

Then make:

make -j4

Try to use as many cores as you can.

Then make install:

sudomakeinstall

Use clang++-V to view the following:

3.3 (tags/RELEASE_33/final)

Target: x86_64-unknown-linux-gnu

Thread model: posix

At this point clang can be used normally,clang by default is the C + + library gcc libstdc++. Clang usage is similar to GCC, if you want to use C++11:

clang++ -std=c++11 [input]

If you want to use LLVM own libc++, you need the following steps (a little trouble):

Before entering the extracted LIBCXX-3.3.SRC:

cd libcxx-3.3.src/lib

./buildit

Then you can see the libc++.so.1.0 file below the Libcxx-3.3.src/lib, which is libc++ 's dynamic library.

Follow the steps below to put libc++.so.1.0 under/usr/lib and create several links:

sudocp ./libc++.so.1.0 /usr/lib

cd /usr/lib

sudoln -sf /usr/lib/libc++.so.1.0 libc++.so

sudoln -sf /usr/lib/libc++.so.1.0 libc++.so.1

Then copy the Libcxx-3.3.src/include directory to the/USR/INCLUDE/C++/V1 (this address is the clang default lookup directory, if the directory does not exist then create it yourself):

cp -r libcxx-3.3.src/include/ /usr/include/c++/v1

Supposedly, after that, it is possible to use libc++ in the following way:

clang++ -stdlib=libc++ -std=c++11 [input]

But when I compile this side, I am prompted to find the header file, need to manually add-i/usr/include/c++/v1/:

clang++ -stdlib=libc++ -std=c++11 -I/usr/include/c++/v1/ [input]

When running, the link error is also indicated: error while loading shared Libraries:libc++.so.1:cannot open Shared object File:no such file or director Y.

The workaround is to include the following environment variables in the ~/.basrch:

export LD_LIBRARY_PATH=/usr/lib:/usr/local/lib

Restart the shell will be able to run normally, the above to find the header file and link errors are due to the use of libc++, if you use the default libstdc++ do not have these problems .

OK, although the use of a little trouble, but write a makefile do not have to knock so long command, enjoy!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.