Building Clang and libc++ on Ubuntu Linux

您所在的位置:网站首页 礼品团购是什么意思 Building Clang and libc++ on Ubuntu Linux

Building Clang and libc++ on Ubuntu Linux

#Building Clang and libc++ on Ubuntu Linux| 来源: 网络整理| 查看: 265

Building Clang and libc++ on Ubuntu Linux

Posted on January 17, 2013 by Sol

Updated on 26 January 2014 for Ubuntu 12.04.4 and Clang 3.4.

Clang with libc++ represents today a viable alternative to GCC for C and C++ programmers. I make no claim that Clang with libc++ is necessarily superior to GCC with libstdc++, but it is definitely a more feature complete C++11 alternative. According to the libc++ website, libc++ is 100% complete C++11 implementation on Apple’s OS X and, from my tests, works equally well on Linux. Even if you plan to ship your C++ application compiled with GCC, I think it is a good test to check your app for errors by building it with a different compiler and library.

In this short post, I’m going to show you how to build the latest Clang and libc++ on a Linux box. I’ve tested this procedure on Ubuntu 12.04.4, Ubuntu 12.10 and Linux Mint 14.

Let’s start by updating your Linux system (this is a recommended but optional step), open a Terminal and paste the next two lines:

sudo apt-get update

sudo apt-get upgrade

Now, let’s install some additional, but necessary, apps:

sudo apt-get install g++ subversion cmake

Next step, is to get the latest version of Clang and LLVM:

cd ~

mkdir Clang && cd Clang

svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm

cd llvm/tools

svn co http://llvm.org/svn/llvm-project/cfe/trunk clang

and to build Clang and LLVM:

cd ..

cd ..

mkdir build && cd build

../llvm/configure --prefix=/usr/clang_3_4 --enable-optimized --enable-targets=host --disable-compiler-version-checks

make -j 8

The above step will take some time …

Let’s install Clang:

sudo make install

In order to be able to use Clang we’ll need to add it to our system path, you can do this with:

export PATH=/usr/clang_3_4/bin:$PATH

or, to permanently add Clang to your system path, paste the above line at the end of your .bashrc file. If you don’t know how to find .bashrc, try this:

cd ~

gedit ~/.bashrc

. .bashrc

For building libc++, we’ll need the include path used by your system C++ compiler and the target platform, we can get these with:

echo | g++ -Wp,-v -x c++ - -fsyntax-only

This is the result of the above line on my system:

sol@sols:~$ echo | g++ -Wp,-v -x c++ - -fsyntax-only

ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"

ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../x86_64-linux-gnu/include"

#include "..." search starts here:

#include ... search starts here:

/usr/include/c++/4.6

/usr/include/c++/4.6/x86_64-linux-gnu/.

/usr/include/c++/4.6/backward

/usr/lib/gcc/x86_64-linux-gnu/4.6/include

/usr/local/include

/usr/lib/gcc/x86_64-linux-gnu/4.6/include-fixed

/usr/include/x86_64-linux-gnu

/usr/include

End of search list.

sol@sols:~$

The first highlighted line from above gives us the include path and the second line the target platform (a 64 bits Linux system). As a side note



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3