加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何使用autotools使用clang和选项-std = c 11编译项目

发布时间:2020-12-16 07:16:39 所属栏目:百科 来源:网络整理
导读:我正在使用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} breakdoneif !
我正在使用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一样).

有人可以帮我弄清楚我做错了什么.

解决方法

好的,经过一些调查后我得到了答案.
首先,在configure.ac中我必须设置我使用的语言:

AC_LANG([C])
AC_LANG([C++])

然后,已经有一个autoconf宏来检查C编译器中的C 11支持:AX_CXX_COMPILE_STDCXX_11.

所以,点这个链接:https://www.gnu.org/software/automake/manual/html_node/Local-Macros.html,
我必须创建一个m4文件夹并将宏定义放在里面.继续进行的最佳方法是仅下载更通用的ax_cxx_compile_stdcxx.m4文件(而不是ax_cxx_compile_stdcxx_11.m4).
所以,总是在configure.ac我写道:

AC_CONFIG_MACRO_DIR([m4])

m4_include([m4/ax_cxx_compile_stdcxx.m4])
AX_CXX_COMPILE_STDCXX(11,noext,mandatory)

和Voilà.一切都很好,至少在我测试的机器上.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读