Soroush Rabiei
Soroush Rabiei

Reputation: 10878

C++11 support in GNU automake

I'm trying to port buildsystem of my project to GNU autotools. The code need to be compiled with -std=c++11 or -std=c++0x flag. I want my configure script to check if compiler supports C++11 or not. I tried adding AX_CHECK_COMPILE_FLAG([-std=c++0x], [CXXFLAGS="$CXXFLAGS -std=c++0x"]) to configure.ac file but configure fails with this error:

 ...
./configure: line 2732: syntax error near unexpected token `-std=c++0x,'
./configure: line 2732: `AX_CHECK_COMPILE_FLAG(-std=c++0x, CXXFLAGS="$CXXFLAGS -std=c++0x")'

Upvotes: 2

Views: 3661

Answers (2)

Brett Hale
Brett Hale

Reputation: 22388

Hopefully there will be more comprehensive support for C++11 in future autoconf releases. In the mean time, I use a C++11 source test from ax_cxx_compile_stdcxx_11.m4 in the GNU autoconf archive:

AC_PROG_CXX
AC_LANG_PUSH([C++])

AC_COMPILE_IFELSE([AC_LANG_SOURCE(
  [[template <typename T>
    struct check
    {
      static_assert(sizeof(int) <= sizeof(T), "not big enough");
    };

    typedef check<check<bool>> right_angle_brackets;

    int a;
    decltype(a) b;

    typedef check<int> check_type;
    check_type c;
    check_type&& cr = static_cast<check_type&&>(c);]])],,
  AC_MSG_FAILURE(['$CXX $CXXFLAGS' does not accept ISO C++11]))

Upvotes: 3

v154c1
v154c1

Reputation: 1698

The error you're getting seems to come from AX_CHECK_COMPILE_FLAG not being expanded in your configure script. You can verify whether it is expanded by grepping AX_CHECK_COMPILE_FLAG in configure. If the grep finds it there, then it is not expanded.

You can also check it by looking into file aclocal.m4, where aclocal should copy it's definition.

The definition of this macro is not included in basic autoconf package, but in the autoconf archives. So you're probably missing this package. (Exact name of the package may differ between distributions, it is sys-devel/autoconf-archive in Gentoo and it seems to be autoconf-archive in Debian and Ubuntu).

Upvotes: 1

Related Questions