我安装了两个 gcc(同样适用于 g++)版本。较新的是默认的:
/usr/bin/gcc # 4.9.2
/usr/bin/gcc-4.4 # 4.4.7
对于我的 make 命令,我想使用 gcc-4.4/g++-4.4。
我已经尝试了这三种变体,但似乎都不起作用:
export CC="gcc-4.4"
export CPP="g++-4.4"
export CC=/usr/bin/gcc-4.4
export CPP=/usr/bin/g++-4.4
export gcc=/usr/bin/gcc-4.4
export g++=/usr/bin/g++-4.4
Makefile 定义:
# Compiler Options
CC = gcc
CPP = g++
LD = g++
Makefile使用的编译器还是4.9.2。如何使用 4.4.7?
最佳答案
GNU Make manual, 6.10 Variables from the Environment :
Variables in
make
can come from the environment in whichmake
is run. Every environment variable that make sees when it starts up is transformed into a make variable with the same name and value. However, an explicit assignment in the makefile, or with a command argument, overrides the environment. (If the-e
flag is specified, then values from the environment override assignments in the makefile. But this is not recommended practice.)
推荐的做法是在 make
命令行上传递这些变量:
$ make CC=gcc-4.4 CPP=g++-4.4 CXX=g++-4.4 LD=g++-4.4
旁注是 CXX
用于编译 C++ 代码,而 CPP
用于预处理。 makefile 的作者将 CPP
与 CXX
混淆了,或者 makefile 确实使用 CPP
来生成依赖项,这在过去十年中一直是不必要的或者。参见 this了解更多详情。
关于c++ - 在 shell 中为 make 设置 GCC 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39854114/