2012-06-14 64 views
0

在我的机器中,我们以root用户身份安装了GCC 4.1.2,但是为了编译LLVM和clang,我需要更高版本的GCC。所以我下载了并且在我的本地目录上安装了GCC 4.5.0。如何使用多个GCC-LLVM和clang

如何使现有程序引用GCC 4.5.0库和包含。

> gcc --version 
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46) 
Copyright (C) 2006 Free Software Foundation, Inc. 
This is free software; see the source for copying conditions. There is NO 
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 

> which gcc 
/usr/bin/gcc 

> setenv PATH gcc-4.5.0/bin/gcc/gcc-4.5.0/bin:$PATH 

> gcc --version 
gcc (GCC) 4.5.0 
Copyright (C) 2010 Free Software Foundation, Inc. 
This is free software; see the source for copying conditions. There is NO 
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 

> which gcc 
gcc-4.5.0/bin/gcc/gcc-4.5.0/bin/gcc 

难道只是设置系统路径将帮助我或者是还有什么需要对现有的代码来引用GCC 4.5.0套房呢?

gcc-4.5.0/bin/gcc/gcc-4.5.0/> ls -l 
total 24 
drwxrwxr-x 2 prasad ppusers 4096 Jun 13 21:32 bin 
drwxrwxr-x 3 prasad ppusers 4096 Jun 13 21:32 include 
drwxrwxr-x 3 prasad ppusers 4096 Jun 13 21:32 lib 
drwxrwxr-x 2 prasad ppusers 4096 Jun 13 21:32 lib64 
drwxrwxr-x 3 prasad ppusers 4096 Jun 13 21:32 libexec 
drwxrwxr-x 6 prasad ppusers 4096 Jun 13 21:32 share 
+0

我会建议你把路径放到GCC_last_的本地拷贝中放在'$ PATH'中,也就是'export PATH = $ PATH:/ your/local/path'。而用'gcc-4.5'调用你的编译器。这样您仍然可以为系统构建应用程序以及您自己的应用程序。 –

+0

但这根本不是目标。我需要仅使用GCC 4.5.0版编译代码 – Prakash

+0

是的,您需要编译具有特定版本的_your_代码,但为_system_编译的代码应该使用系统提供的编译器。这是因为系统工具中可能存在不兼容的情况。我的建议当然可以和cobbal的答案结合起来,所以你按照我的建议设置PATH,然后做'CC = gcc-4.5 make'。 –

回答

1

这样做的最好方法因构建系统而异。

对于化妆(可能还有其他系统)的C编译器在CC变量指定的,所以你可以叫

CC=/path/to/new/gcc make 

如果该项目使用从autoconf的配置脚本,你可以使用类似的

东西
./configure CC=/path/to/new/gcc