【发布时间】:2016-06-05 16:19:57
【问题描述】:
我正在使用 C 和 C++ 代码开发软件。我最近在 c++11 标准中添加了一些代码。 在 configure.ac 我写道:
for f in '-std=c++11' '-std=c++11 -stdlib=libc++'
do
AX_CHECK_COMPILE_FLAG([$f], [CXXFLAGS="$CXXFLAGS $f" stdpass=true], [], [], [])
${stdpass-false} && break
done
if ! "${stdpass-false}"; then
AC_MSG_ERROR([Unable to turn on C++11 mode with this compiler])
fi
使用 gcc 我没问题,一切顺利,选项 -std=c++11 仅适用于 g++ 而不适用于 gcc。 如果我尝试配置:
CC=clang ./configure
我有以下错误:
checking whether C compiler accepts -std=c++11... no
checking whether C compiler accepts -std=c++11 -stdlib=libc++... no
configure: error: Unable to turn on C++11 mode with this compiler
这就像选项被应用在 C 编译器上,而不仅仅是在 clang++ 上(就像它使用 gcc 完成的一样)。
谁能帮我弄清楚我做错了什么。
【问题讨论】:
-
检查
config.log以查看实际的编译命令,以及产生的错误。 -
那个“检查 C 编译器是否...”消息让我觉得你忘记了to set the language。
-
另外,你应该使用
CXX=clang++ ./configure来设置C++编译器。 -
Joachim: 似乎把两者都放在:AC_LANG([C]), AC_LANG([C++]) 效果很好!!!你应该把它写在答案部分;)谢谢
-
已经有一个 autoconf 宏来检查 C++ 编译器中的 C++11 支持:AX_CXX_COMPILE_STDCXX_11。要在
configure.ac中使用,请将其放在项目的m4目录中。
标签: c++ c c++11 clang autotools