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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 11:37:38  来源:igfitidea点击:

Make GNU make use a different compiler

c++cmakefile

提问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 CCand CXX, which are used for compiling C and C++ files respectively. By default they use the values ccand g++

您可以设置环境变量CCCXX,分别用于编译 C 和 C++ 文件。默认情况下,他们使用值ccg++

回答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 CCvalue into the makefile that it generates, so you don't need to manuallyedit it, and you can just run makeby itself thereafter (instead of giving the custom CCvalue 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 makeutility or set them in the environment before building.

使用变量作为编译器程序名称。
要么将新定义传递给make实用程序,要么在构建之前将它们设置在环境中。

See Using Variables in Make

请参阅在 Make 中使用变量