C++ 使 GNU make 使用不同的编译器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2969222/
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
Make GNU make use a different compiler
提问by Clark Gaebel
How can I make GNU Make use a different compiler without manually editing the makefile?
如何在不手动编辑 makefile 的情况下让 GNU Make 使用不同的编译器?
回答by jonescb
You should be able to do something like this:
你应该能够做这样的事情:
make CC=my_compiler
This is assuming whoever wrote the Makefile used the variable CC.
这是假设编写 Makefile 的人使用了变量 CC。
回答by Michael Mrozek
You can set the environment variables CC
and CXX
, which are used for compiling C and C++ files respectively. By default they use the values cc
and g++
您可以设置环境变量CC
和CXX
,分别用于编译 C 和 C++ 文件。默认情况下,他们使用值cc
和g++
回答by Rob Kennedy
If the makefile is written like most makefiles, then it uses $(CC)
when it wishes to invoke the C compiler. That's what the built-in rules do, anyway. If you specify a different value for that variable, then Make will use that instead. You can provide a new value on the command line:
如果 makefile 像大多数 makefile 一样编写,那么它$(CC)
在希望调用 C 编译器时使用。无论如何,这就是内置规则的作用。如果您为该变量指定不同的值,则 Make 将使用该值。您可以在命令行上提供一个新值:
make CC=/usr/bin/special-cc
You can also specify that when you run configure
:
您还可以在运行时指定configure
:
./configure CC=/usr/bin/special-cc
The configuration script will incorporate the new CC
value into the makefile that it generates, so you don't need to manuallyedit it, and you can just run make
by itself thereafter (instead of giving the custom CC
value on the command line every time).
配置脚本会将新CC
值合并到它生成的 makefile 中,因此您无需手动编辑它,make
此后您可以自行运行(而不是CC
每次都在命令行上提供自定义值)。
回答by ladenedge
Many makefiles use 'CC' to define the compiler. If yours does, you can override that variablewith
许多 makefile 使用“CC”来定义编译器。如果你做,你可以覆盖该变量与
make CC='/usr/bin/gcc'
回答by Thomas Matthews
Use variables for the compiler program name.
Either pass the new definition to the make
utility or set them in the environment before building.
使用变量作为编译器程序名称。
要么将新定义传递给make
实用程序,要么在构建之前将它们设置在环境中。
请参阅在 Make 中使用变量