[英]Set GCC path in makefile
Whenever I am building my package it uses /usr/bin/g++
(system compiler).每当我构建我的包时,它都会使用
/usr/bin/g++
(系统编译器)。 I want to build my package with C++11 constructs.我想用 C++11 构造构建我的包。 I have tried
-std=c++11
option but with system compiler it says unrecognized option.我试过
-std=c++11
选项,但系统编译器显示无法识别的选项。 I want to build my package from a different gcc
compiler which will get downloaded as part of my package dependency.我想从不同的
gcc
编译器构建我的包,它将作为我的包依赖项的一部分下载。
So, how can I specify the location of gcc
compiler in Makefile?那么,如何在Makefile中指定
gcc
编译器的位置呢?
There are multiple ways to achieve what you are looking for:有多种方法可以实现您的目标:
Setting the environment variable CXX
just for the process that will run make
:仅为将运行
make
的进程设置环境变量CXX
:
$ CXX=/path-to-your-compiler/g++ make
Exporting the environment variable CXX
in your shell:在 shell 中导出环境变量
CXX
:
$ CXX=/path-to-your-compiler/g++ $ export CXX $ make
Setting CXX
at make
's command-line:在
make
的命令行设置CXX
:
$ make CXX=/path-to-your-compiler/g++
Inside your makefile:在你的 makefile 中:
CXX := /path-to-your-compiler/g++
Note that setting the variable at make
's command line overrides the other values, and variables set inside the makefile override the ones obtained from the environment (unless the command-line option -e
or --environment-overrides
is provided).请注意,在
make
的命令行中设置变量会覆盖其他值,并且在 makefile 中设置的变量会覆盖从环境中获得的变量(除非提供了命令行选项-e
或--environment-overrides
)。
Inside your makefile, you can still override any value set by other means by using the override
directive:在您的 makefile 中,您仍然可以使用
override
指令override
通过其他方式设置的任何值:
override CXX := /path-to-your-compiler/g++
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.