【问题标题】:C++11 in CDT with autotools带有自动工具的 CDT 中的 C++11
【发布时间】:2013-07-30 13:08:11
【问题描述】:

我尝试通过在我的 configure.ac 文件中添加 AX_CXX_COMPILE_STDCXX_11 在 CDT 中启用 C++11。我试过在文件中移动它,这似乎是唯一不会出错的地方。我什至尝试添加可选的noext 标志,但这给了我一个语法错误。

我要编译的代码是:

#include <iostream>
#include <memory>

void
print_hello(){
    std::unique_ptr<char[]> cha;
    std::cout << "11?" << std::endl;
}

unique_ptr 当然是 c++11 的特性。

这就是我的 configure.ac 的样子:

dnl Process this file with autoconf to produce a configure script.

AC_PREREQ(2.64)
AC_INIT(fooProj, 1.0)

AC_CANONICAL_SYSTEM

AC_PROG_CXX
AC_LANG([C++])
AX_CXX_COMPILE_STDCXX_11

dnl Initialize automake
AM_INIT_AUTOMAKE

dnl this allows us specify individual liking flags for each target
AM_PROG_CC_C_O 

dnl Initialize Libtool
LT_INIT

dnl Check if Libtool is present
dnl Libtool is used for building share libraries 
AC_PROG_LIBTOOL

AC_CONFIG_FILES(Makefile
                exampleProgram/Makefile
                libTestLib/Makefile
                include/Makefile)
AC_OUTPUT

【问题讨论】:

  • 你得到什么样的错误?将-std=c++11 传递给编译器还不够吗?
  • 我得到的错误是 unique_ptr 不是 std 的一部分。编译器标志就足够了,但这似乎不是正确的自动工具方式。
  • 这个错误来自 Eclipse 吗?我的意思是,尽管有错误,代码是否可以编译?
  • 不,它来自 g++,编译器没有通过 -std 标志。
  • 好的,现在我明白问题所在了。

标签: c++ c++11 eclipse-cdt autotools


【解决方案1】:

如果您只想将您的代码编译为 C++11 标准,然后清理您的构建,然后将 AM_CXXFLAGS = -std=c++11 添加到您的源代码所在的 Makefile.am,然后重新构建。为此,configure.ac 中的 AX_CXX_COMPILE_STDCXX_11 是不必要的。

【讨论】:

  • 但是autotools不会检查编译器是否支持C++11,还是不正确?
  • Autotools 不会检查编译器是否支持 C++11;但如果不是,编译器将拒绝 -std=c++11 选项并停止。
  • 那么我想我在另一个网页上看到的内容是错误的。配置检查似乎更正确。谢谢。
  • 我同意进行配置检查会更正确。我刚刚学会了使用 autotools 宏走阻力最小的道路:(
【解决方案2】:

您需要 gnu 网站 [1] 上此页面的 m4 宏。将其保存为 ax_cxx_compile_stdcxx_11.m4 在您的项目根目录中。

[1]:http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html""

【讨论】:

    【解决方案3】:
    sudo apt-get install autoconf-archive
    

    【讨论】:

      猜你喜欢
      • 2012-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-16
      • 1970-01-01
      • 1970-01-01
      • 2012-03-05
      相关资源
      最近更新 更多