makefile - Autotools 的默认编译器标志

标签 makefile autoconf automake

我想知道如何设置默认编译器/链接器/等。如果我使用 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/

相关文章:

c++ - 如何快速生成C++项目树状结构

linux - 无法为 ARM 交叉编译 postgresql 12.2

autotools - 使用 PKG_CHECK_MODULES 时,autoconf 生成的 Makefile 不传递库头的标志

centos - 为什么 autogen.sh 即使使用正确的 autoconf 也会失败?

c++ - Automake : what are the valid values for *_la_LDFLAGS in Makefile. 上午?

c++ - makefile 命令在第一个目标之前开始

Makefile 在目标中设置变量

linux - 构建 Pulseaudio-11.1 和 intltool >= 0.35.0 错误

build - 条件子目录对象

autotools - 在配置脚本中检查 automake/autoconf 版本