【问题标题】:Autotools check for C++11自动工具检查 C++11
【发布时间】:2012-08-08 05:01:18
【问题描述】:

我使用AX_CXX_COMPILE_STDCXX_0X(可以查看 autoconf-archive)来检查编译器的 c++11 功能。它正确地确定需要-std=c++0x,但不会将其添加到CXXFLAGS。我查看了宏源,它实际上会检查但随后会恢复以前的标志。

我应该怎么做才能将CXXFLAGS 设置为能够编译c++11 源代码?

只是将-std=c++0x 添加到AM_CXXFLAGS 不是很好的解决方案,因为我想将编译器在C++11 模式下编译的负担交给autoconf 开发人员,而不是我。

【问题讨论】:

    标签: c++ c++11 autotools autoconf


    【解决方案1】:

    您要查找的内容已被制作为AX_CXX_COMPILE_STDCXX_11,是autoconf-archive 的一部分。它将向环境添加所需的选项(以前通过CXXFLAGS,现在通过CXX),如果没有可用的 C++11 支持,则会出错。

    【讨论】:

    • configure.ac:15: error: AC_LANG_ASSERT: current language is not C++: C ../../lib/autoconf/lang.m4:156: AC_LANG_ASSERT is expanded from... m4/ax_cxx_compile_stdcxx_11.m4:48: AX_CXX_COMPILE_STDCXX_11 is expanded from... configure.ac:15: the top level autom4te: /usr/bin/m4 failed with exit status: 1 aclocal: error: /usr/bin/autom4te failed with exit status: 1 autoreconf: aclocal failed with exit status: 1 我把它放在AC_PROG_CXX 之后。我做错了什么?
    • @illusionoflife AC_PROG_CXX 不应该这样做,因为它会弄乱具有 C 和 C++ 检查的配置脚本。大多数 autoconf 检查都依赖于 C。添加 AC_LANG 是正确的做法。
    • 这里的问题: ax_cxx_compile_stdcxx_11.m4 应该设置 CXXFLAGS(就像它一样)还是 AM_CXXFLAGS?问题是我无法在 make 行上进行 CXXFLAGS 的用户级设置,例如: make CXXFLAGS="-g -O0 -Wall" 因为 -std=c++11 标志丢失而失败。
    • 为了让它工作,我还安装了 autoconf-archive,据我所知,这是宏“生活”的地方。
    • @MicroVirus 对,这就是我从 autoconf-archive 链接到文档的原因,但最好明确提及。感谢您的评论。
    【解决方案2】:

    一般来说,您可以编译一个简单的代码并根据编译结果设置一个变量

    DIALECT="-std=c++14"
    echo 'int main() {return 0;}' > ./log.cpp && $CXX -std=c++14 ./log.cpp || $DIALECT="no"
    
    if test $DILAECT = no; then
        AC_MSG_ERROR([c++ compiler does not support c++14])
    else
        echo $DILAECT
    fi
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-31
      • 2012-04-30
      • 1970-01-01
      • 2011-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多