无法使自动制作使用 C++11
Can't make automake to use C++11
我正在做一些项目,似乎我不能使自动制作脚本使用c++ 11。
在我的项目的rootdir中,我有文件Makefile.am
,看起来像这样(它是由eclipse自动生成的):
SUBDIRS=src
然后在/rootdir/src中我有Makefile。它看起来像这样:
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
,但我不明白为什么。它用的是完全不同的东西。这是我的配置。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
来配置。Ac脚本,但错误仍然发生。知道怎么解决这个问题吗?
我使用的是Ubuntu 12.04 x64和Eclipse (Version: Mars Release (4.5.0))
一个快速的测试显示,对于我来说,使用类似的配置,一切都工作正常,所以您将不得不通过卷起袖子,查看最终的Makefile
来弄清楚Makefile发生了什么。
查看汽车-d Makefile
的内部。您应该在其中找到.cpp.o的最终构建规则。搜索"。cpp.o"。它应该看起来像这样:
.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
中是如何定义的。
在我的例子中,对于我的简单测试,它很简单:
AM_CXXFLAGS = -std=gnu++11
在我的例子中,它只是,在你的例子中,显然你会有其他标志在那里。
就是这样。automake-d Makefile显然非常大,看起来很吓人,但是当您仔细研究它时,它根本不是很复杂。
这将是两件事中的一件。Makefile的另一部分。am修改AM_CXXFLAGS
的值,或者修改CXXCOMPILE
宏。关于automake的一件事是,如果宏或变量被重新定义,它通常不会报错。它将使用变量的最终值生成最终的Makefile
。所以,我猜在稍后的某个地方,在你的Makefile。在这里,您将AM_CXXFLAGS
设置为其他内容,而没有意识到它。
注意:实际的宏经常被调整,随着automake
的每个后续版本,所以你的宏可能看起来略有不同,但一般的想法应该是一样的。.cpp.o
构建规则运行CXXCOMPILE
宏,它使用AM_CXXFLAGS
。
首先,automake
在执行automake
之前不会生成Makefile
所以,我添加了-std=gnu++11来支持c++ 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
没有生成包含-std=gnu++11
语句的Makefile
。
所以,你所需要做的就是,在你的项目根目录下使用命令行:
$ autoreconf
这将自动执行aclocal
, autoconf
, automake
等等…
- 关于检查
-std=c++11
标志
最好使用ax_cxx_compile_stdcxx_11.m4
要使用它,您需要从上面的链接下载它并将其设置在$(project_top)/m4/
接下来,在configure中编写如下代码。交流:
AX_CXX_COMPILE_STDCXX_11([noext], [mandatory])
和exec,你可以检查是否可能使用c++ 11的特性在平台
$ autoreconf -vi -I m4
$ ./configure
- MSVC是否支持C++11样式的属性而不是__declspec
- 创建LinkedList退出,返回代码为-11(SIGSEGV)
- 我可以将一个用clang c++11编译的对象与另一个用c++17编译的对象链接起来吗
- 继承:构造函数,初始化C++11中基类的类C数组成员
- 如何将模板转换为C++11之前的模板
- c++11评估顺序(未定义的行为)
- C++中的VLA,扩展名为std=C++11
- 代码在我的计算机上运行良好,但是在将其提交给coursera时遇到未知的信号11问题
- "类模板示例<int>;"语句对 C++11 是什么意思?
- this_thread::sleep_for和计时时钟之间的关系是否由C++11标准指定
- 如何使用lock_guard在c++11中实现scoped_lock功能
- C++11 中不同类型的对象的 std::array 的替代方案
- 为什么 -mmacosx-version-min=10.10 不阻止使用标记为从 10.11 开始的函数?
- 为什么我的C++代码中出现'Segmentation Fault: 11'行?
- 强枚举类型定义:Clang Bug 还是 C++11 标准不确定性?
- 别名模板的专业化 C++11 中没有开销的最佳替代方案
- STLPort using C++11
- Qt 5.11.2 (Clang 8.0 (Apple), 64 位), 找不到 QJSEngine 文件
- 在 C++11 中,如何查找并返回以给定字符串开头的字符串向量中的所有项?
- C++11 迭代向量的新方法?