Can't use automake to use C ++ 11

I am working on some project and it seems that I cannot use an automake script to use C ++ 11.

In the root directory of my project, I have a file Makefile.am

that looks like this (it was automatic eclipse):

SUBDIRS=src

      

Then in / rootdir / src I have a Makefile.am that looks like this:

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

      

So I added -std=gnu++11

for C ++ 11 support, but I still get this error:

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 \
  ^

      

And from this error, I can see that g ++ is not using -Wall -fPIC -std=gnu++11

, but I don't understand why. He is using something completely different. This is my configure.ac script which is located in the root of my project

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

      

I also tried adding AX_CXX_COMPILE_STDCXX_11

to the configure.ac script, but the error still happens. Any idea how to fix this?

I am using Ubuntu 12.04 x64 and Eclipse (version: Mars Release (4.5.0))

+3


source to share


2 answers


A quick test shows that everything is working correctly for me, with a similar configuration, so you'll need to figure out what's going on with your Makefile by simply rolling up your sleeves looking at your final one Makefile

.

Review automaton-d Makefile

. You should find somewhere within it, the final build rule for .cpp.o. Search for ".cpp.o". It should look something like this:

.cpp.o:
    $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
    $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po

      

After checking this next step, you need to look at what your macro is defining CXXCOMPILE

. It should look something like this:

CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
    $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)

      

And your used variable AM_CXXFLAGS

. Finally, confirm how it is defined in fact Makefile

.



In my case, for my simple test, it was just:

AM_CXXFLAGS = -std=gnu++11

      

In my case this was exactly the case, in your case, obviously, you will have your other flags there.

What is it. The automake-d Makefile is obviously quite large and looks intimidating, but when you get down to it, it's not very difficult.

It will be one of two things. Any other part of your Makefile.am will compress the value AM_CXXFLAGS

, or the macro CXXCOMPILE

gets confused. One thing about automake is that it doesn't complain at all if a macro or variable is being overridden. It will just generate the final Makefile

using the final value of the variable. So, I would guess that somewhere later, in your Makefile.am, you set AM_CXXFLAGS

to something else without knowing it here.

Note: the actual macros are often customized with each sequential version automake

, so yours might look slightly different, but the general idea should be the same. The build rule .cpp.o

runs a macro CXXCOMPILE

that uses AM_CXXFLAGS

.

+1


source


First of all, it automake

won't generate Makefile

until it executesautomake

So, I added -std = gnu ++ 11 for C ++ 11 support, but I still get this error:

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 \
^

      

  • Your log says there is no instruction in gcc `compile time -std=gnu++11

    . In other words, automake

    did not generate a Makefile

    containing instruction -std=gnu++11

    .

So, all you have to do is at the root of your command line project:

$ autoreconf

      



It will automatically perform aclocal

, autoconf

, automake

and blah blah ...

  • About checking the flag -std=c++11

it is useful to use ax_cxx_compile_stdcxx_11.m4
To use it you need to download it from the above link and install it in $ (project_top) / m4 /
Then you write like below in configure.ac :

AX_CXX_COMPILE_STDCXX_11([noext], [mandatory])

      

And exec, you can check if it is possible or not to use the C ++ 11 feature on the platform

$ autoreconf -vi -I m4
$ ./configure

      

0


source







All Articles