redhat6.2 clang编译环境搭建(采用源码包编译安装)

1. About clang++

office site:http://clang.llvm.org/

A major focus of our work on clang is to make it fast, light and scalable. The library-based architecture of clang makes it straight-forward to time and profile the cost of each layer of the stack, and the driver has a number of options for performance analysis. Many detailed benchmarks can be found online.

2. System environment configuration 

Getting Introduction from the office website:

Compiling LLVM requires that you have several software packages installed. The table below lists those required packages. The Package column is the usual name for the software package that LLVM depends on. The Version column provides “known to work” versions of the package. The Notes column describes how LLVM uses the package and provides other details.

 

PackageVersionNotes
GNU Make 3.79, 3.79.1 Makefile/build processor
GCC >=4.7.0 C/C++ compiler1
python >=2.5 Automated test suite2
GNU M4 1.4 Macro processor for configuration3
GNU Autoconf 2.60 Configuration script builder3
GNU Automake 1.9.6 aclocal macro generator3
libtool 1.5.22 Shared library manager3
zlib >=1.2.3.4 Compression library4

local System configuration analysis :

# /usr/bin/gcc4.4.5 --version
gcc4.4.5 (GCC) 4.4.5 20110214 (Red Hat 4.4.5-6)

# python -V
Python 2.6.6

# make -v
GNU Make 3.81

# automake --version
automake (GNU automake) 1.11.1

# libtool --version
ltmain.sh (GNU libtool) 2.2.6b
Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996

 

3. gcc upgrade

3.1 gmp,mpfr,mpc installation

wget https://ftp.gnu.org/gnu/gmp/gmp-5.1.3.tar.bz2
wget http://www.mpfr.org/mpfr-current/mpfr-3.1.2.tar.gz
wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.2.tar.gz
tar jxvf gmp-5.1.3.tar.bz2
tar zxvf mpfr-3.1.2.tar.gz
tar zxvf mpc-1.0.2.tar.gz

cd gmp-5.1.3
./configure --enable-cxx CPPFLAGS=-fexceptions  
make; make install
cd ../mpfr-3.1.2; ./configure
make; make install
cd ../mpc-1.0.2; ./configure
make; make install

3.2 gcc upgrade

wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.2/gcc-4.8.2.tar.bz2
tar -xvjf gcc-4.8.2.tar.bz2
cd gcc-4.8.2mkdir gcc-4.8.2-build
cd gcc-4.8.2-build
../configure --prefix=/usr/local/gcc-4.8.2 --enable-languages=c,c++
make make install

notice:change the links in /usr/lib  & /usr/bin [only need make some softlinks to the directory, incase of pollute the original files . You can remove the softlinks while necessary which is not commentary ] 

cd /usr/bin/
# mv gcc gcc4.4.5
# mv g++ g++4.4.5

ln -sf /usr/local/gcc-4.8.2/bin/gcc gcc
ln -sf /usr/local/gcc-4.8.2/bin/g++ g++
ln -sf /usr/local/gcc-4.8.2/lib64/libstdc++.so.6.0.18 /usr/lib64/libstdc++.so.6

4. make building files

4.1  Checkout LLVM:
Change directory to where you want the llvm directory placed.
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
4.2 Checkout Clang:
cd llvm/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
cd ../..
4.3 Checkout extra Clang Tools: (optional)
cd llvm/tools/clang/tools
svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra
cd ../../../..
4.4 Checkout Compiler-RT:
cd llvm/projects
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
cd ../..
4.5 Build LLVM and Clang:
mkdir build (for building without polluting the source dir)
cd build
../configure --prefix=/usr/local/clang --enable-optimized 
make

4.6 error resolved

checking for x86_64-unknown-linux-gnu-gcc... /data/installs/gcc-4.7.4/host-x86_64-unknown-linux-gnu/gcc/xgcc -B/data/installs/gcc-4.7.4/host-x86_64-unknown-linux-gnu/gcc/ -B/usr/local/gcc-4.7.4/x86_64-unknown-linux-gnu/bin/ -B/usr/local/gcc-4.7.4/x86_64-unknown-linux-gnu/lib/ -isystem /usr/local/gcc-4.7.4/x86_64-unknown-linux-gnu/include -isystem /usr/local/gcc-4.7.4/x86_64-unknown-linux-gnu/sys-include   
checking for suffix of object files... configure: error: in `/data/installs/gcc-4.7.4/x86_64-unknown-linux-gnu/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.
make[2]: *** [configure-stage1-target-libgcc] Error 1
make[2]: Leaving directory `/data/installs/gcc-4.7.4'
make[1]: *** [stage1-bubble] Error 2
make[1]: Leaving directory `/data/installs/gcc-4.7.4'
make: *** [all] Error 2

resolution: due to the official document, the gcc-4.7.4 can not work normally with the clang++ , which been improved to be a bug

 

resolution:

 

5.  clang environment test

root@192.168.100.252:/data/forilen# cat t.c 
#include <stdio.h>
int main(int argc, char **argv) { printf("hello world\n"); }
root@192.168.100.252:/data/forilen# clang t.c 
root@192.168.100.252:/data/forilen# ls
a.out  for.sh  gerritDir  git  scripts  t.c
root@192.168.100.252:/data/forilen# ./a.out 
hello world

 

6. References

[1]. gcc upgrade: http://my.oschina.net/vaero/blog/210485
[2]. gcc download: http://gcc.parentingamerica.com/releases/ https://gcc.gnu.org/mirrors.html
[3]. clang installation: http://clang.llvm.org/get_started.html#build
[4]. python Introduction:  http://blog.csdn.net/pan_tian/article/details/7684409

 
posted @ 2014-11-21 13:26  forilen  阅读(540)  评论(0编辑  收藏  举报