具有自动工具的CDT中的C++11

C++11 in CDT with autotools

本文关键字:CDT 中的 C++11 工具      更新时间:2023-10-16

我已经尝试在CDT中通过将AX_CXX_COMPILE_STDCXX_11添加到我的config.ac文件来启用C++11。我试着在文件中移动它,这似乎是唯一一个不会出错的地方。我甚至尝试添加可选的noext标志,但这会导致语法错误。

我试图编译的代码是:

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

其中unique_ptr当然是一个c++11特性。

这就是我的配置.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

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

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

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

sudo apt-get install autoconf-archive