我想知道如何设置默认编译器/链接器/等。如果我使用 Autoconf/Automake 组合,则进行标记。
例如,如果我未设置任何内容,则默认编译器标志为“-O2 -g”。我可以用其他东西覆盖它,例如,如果我想调试:
./configure 'CXXFLAGS=-O0 -g'
但我发现默认配置很愚蠢,因为如果我启用优化,调试将变得不可能。因此,如果我运行不带参数的 configure
,默认标志应该是“-O2”或“-O0 -g”。我该怎么做?
编辑:我尝试了以下解决方案:
- 将
progname_CXXFLAGS=whatever
放入 Makefile.am。它不起作用,因为它将标志添加到默认标志中而不是替换它们。 - 将
CXXFLAGS=whatever
放入configure.ac。这可行,但以后我无法覆盖它。
最佳答案
根据autoconf手册(关于AC_PROG_CC
):
If using the GNU C compiler, set shell variable GCC to ‘yes’. If output variable CFLAGS was not already set, set it to -g -O2 for the GNU C compiler (-O2 on systems where GCC does not accept -g), or -g for other compilers. If your package does not like this default, then it is acceptable to insert the line
: ${CFLAGS=""}
after AC_INIT and before AC_PROG_CC to select an empty default instead.
同样,根据autoconf手册(关于AC_PROG_CXX
):
If using the GNU C++ compiler, set shell variable GXX to ‘yes’. If output variable CXXFLAGS was not already set, set it to -g -O2 for the GNU C++ compiler (-O2 on systems where G++ does not accept -g), or -g for other compilers. If your package does not like this default, then it is acceptable to insert the line
: ${CXXFLAGS=""}
after AC_INIT and before AC_PROG_CXX to select an empty default instead.
关于makefile - Autotools 的默认编译器标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3116645/