无法使automake使用C ++ 11

时间:2015-07-26 01:17:46

标签: c++ c++11 autoconf automake

我正在开展一些项目,似乎我无法使用自动脚本来使用C ++ 11。

在我的项目的rootdir中,我有一个文件Makefile.am看起来像这样(它是由eclipse自动生成的):

SUBDIRS=src

然后在/ rootdir / src中我有Makefile.am,如下所示:

AM_CXXFLAGS=-Wall -fPIC -std=gnu++11 -DVERSION=\"$(VERSION)\" -DPROG="\"$(PACKAGE)\""

bin_PROGRAMS = algatorc
algatorc_SOURCES = algatorc.cpp
include_HEADERS = Timer.hpp TestSetIterator.hpp TestCase.hpp ETestSet.hpp EParameter.hpp Entity.hpp ParameterSet.hpp AbsAlgorithm.hpp Log.hpp JSON.hpp JSONValue.hpp

lib_LIBRARIES = libAlgatorc.a
libAlgatorc_a_SOURCES = ParameterSet.cpp TestCase.cpp EParameter.cpp ETestSet.cpp TestSetIterator.cpp Entity.cpp Timer.cpp JSON.cpp JSONValue.cpp AbsAlgorithm.cpp
algatorc_LDADD=libAlgatorc.a

所以,我为C ++ 11支持添加了-std=gnu++11,但我仍然收到此错误:

g++ -DPACKAGE_NAME=\"algatorc\" -DPACKAGE_TARNAME=\"algatorc\" -DPACKAGE_VERSION=\"1.0\" -DPACKAGE_STRING=\"algatorc\ 1.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"algatorc\" -DVERSION=\"1.0\" -I.     -g -O2 -MT algatorc.o -MD -MP -MF .deps/algatorc.Tpo -c -o algatorc.o algatorc.cpp
In file included from /usr/include/c++/4.8/thread:35:0,
                 from Log.hpp:281,
                 from algatorc.cpp:18:
/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support for the \
  ^

从这个错误我可以看出g ++没有使用-Wall -fPIC -std=gnu++11,但我不明白为什么。它完全使用其他东西。 这是我的configure.ac脚本,它位于我项目的rootdir中

AC_PREREQ([2.69])
AC_INIT([algatorc], [0.1], [my_mail])
AC_CONFIG_SRCDIR([src/TestCase.hpp])
#AC_CONFIG_HEADERS([config.h])

LT_INIT
AM_INIT_AUTOMAKE

# Checks for programs.

AC_PROG_CXX

# Checks for libraries.

# Checks for header files.
AC_CHECK_HEADERS([stdlib.h string.h sys/time.h unistd.h wchar.h wctype.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_SIZE_T

# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_MKTIME
AC_CHECK_FUNCS([gettimeofday memset mkdir])

LIBS=-ldl

AC_CONFIG_FILES([Makefile])
AC_OUTPUT

我还尝试将AX_CXX_COMPILE_STDCXX_11添加到configure.ac脚本,但仍会出现错误。知道如何解决这个问题吗?

我正在使用Ubuntu 12.04 x64和Eclipse(版本:Mars Release(4.5.0))

2 个答案:

答案 0 :(得分:1)

快速测试显示一切正常对我来说,具有类似的配置,因此您只需卷起袖子,查看最终{{1}就必须弄清楚Makefile的运行情况。 }}

查看automake-d Makefile。您应该在其中找到某个位置,即.cpp.o的最终构建规则。搜索“.cpp.o”。看起来应该是这样的:

Makefile

验证完成后,下一步是查看您的.cpp.o: $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po 宏的定义。看起来应该是这样的:

CXXCOMPILE

那是你正在使用的CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) 变量。最后,确认它是如何在实际AM_CXXFLAGS中定义的。

就我而言,对于我的简单测试,它只是:

Makefile

在我的情况下,就在你的情况下,显然你会在那里有你的其他旗帜。

就是这样。 automake-d Makefile显然非常庞大,看起来令人生畏,但是当你开始使用它时,它并不是很复杂。

这将是两件事之一。你的Makefile.am的另一部分破坏了AM_CXXFLAGS = -std=gnu++11 的值,或者AM_CXXFLAGS宏被破坏了。关于automake的一件事是,如果重新定义宏或变量,它通常不会抱怨。它只是使用变量的最终值生成最终CXXCOMPILE。所以,我想在以后的某个地方,在你的Makefile.am中,你将Makefile设置为别的东西,而不是在这里知道它。

注意:实际的宏经常被调整,每个连续版本的AM_CXXFLAGS,所以你的看起来可能略有不同,但一般的想法应该是相同的。 automake构建规则运行.cpp.o宏,该宏使用CXXCOMPILE

答案 1 :(得分:0)

首先,automake在执行Makefile之前不会生成automake

  

所以,我为C ++ 11支持添加了-std = gnu ++ 11,但我仍然收到此错误:

g++ -DPACKAGE_NAME=\"algatorc\" -DPACKAGE_TARNAME=\"algatorc\" -DPACKAGE_VERSION=\"1.0\" -DPACKAGE_STRING=\"algatorc\ 1.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"algatorc\" -DVERSION=\"1.0\" -I.     -g -O2 -MT algatorc.o -MD -MP -MF .deps/algatorc.Tpo -c -o algatorc.o algatorc.cpp
In file included from /usr/include/c++/4.8/thread:35:0,
             from Log.hpp:281,
             from algatorc.cpp:18:
/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support for the \
^
  • 您的日志说gcc的编译时间中没有-std=gnu++11的声明。换句话说,automake未生成包含Makefile语句的-std=gnu++11

因此,您需要做的就是在项目根目录中使用命令行:

$ autoreconf

这将自动执行aclocalautoconfautomake并等等等等......

  • 关于检查-std=c++11标志

最好使用ax_cxx_compile_stdcxx_11.m4
要使用它,您需要从上面的链接下载并将其设置为 $(project_top)/ m4 /
接下来,您在 configure.ac

中写下如下
AX_CXX_COMPILE_STDCXX_11([noext], [mandatory])

并且exec,您可以检查是否可以在平台中使用C ++ 11功能

$ autoreconf -vi -I m4
$ ./configure