Linux 在运行 configure 时配置与默认值不同的编译器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10435816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Configuring for a compiler different than the default while running configure
提问by MetallicPriest
I am compiling the glibc library. Before I could do that, I need to run configure
. However, for compiling glibc, I need to use the gcc compiler which is not the default compiler on the machine. The manualsays the following.
我正在编译 glibc 库。在我能做到这一点之前,我需要运行configure
. 但是,为了编译 glibc,我需要使用 gcc 编译器,它不是机器上的默认编译器。该手册指出以下几点。
It may also be useful to set the CC and CFLAGS variables in the environment
when running configure. CC selects the C compiler that will be used, and CFLAGS
sets optimization options for the compiler.
Now my problem is that I don't have any administrative rights on that machine. So how can I use a compiler different than the default.
现在我的问题是我对该机器没有任何管理权限。那么我如何使用不同于默认的编译器。
采纳答案by osgx
On linux anyone can change environment variables of his process; no administrative right are needed.
在 linux 上,任何人都可以更改其进程的环境变量;不需要管理权限。
In bash:
在 bash 中:
export CC="gcc" CFLAGS="-O3 -Wall"
In csh use
在 csh 中使用
setenv CC "gcc"
Any program started in this shell after such command will have CC variable in its environment. (Env vars are remembered by bash, csh or other shell). You can add this command to your ~/.bashrc
file to make this setting permanent.
在此命令之后在此 shell 中启动的任何程序都将在其环境中具有 CC 变量。(环境变量被 bash、csh 或其他 shell 记住)。您可以将此命令添加到您的~/.bashrc
文件中以使此设置永久化。
There are other ways to pass CC to configure too, e.g. in bash it is possible to set environment variable to single command, without remembering:
还有其他方法可以通过 CC 进行配置,例如在 bash 中,可以将环境变量设置为单个命令,而无需记住:
CC="gcc" CFLAGS="-O3 -Wall" ./configure ...
PS and popular ./configure CC=gcc
is not an environment variable change and is specific to configure implementation (but most configures support this)
PS 和流行./configure CC=gcc
不是环境变量更改,而是特定于配置实现(但大多数配置都支持这一点)
回答by Burton Samograd
CC=gcc ./configure will allow you to set the compiler.
CC=gcc ./configure 将允许您设置编译器。
回答by MetallicPriest
Do the following before running configure.
在运行配置之前执行以下操作。
export CC=gcc_your_version
回答by yaman
You can also do this when running make:
您也可以在运行 make 时执行此操作:
make CC=/whatever/compiler