2

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")'
sorush-r
  • 10,490
  • 17
  • 89
  • 173

2 Answers2

3

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]))
Brett Hale
  • 21,653
  • 2
  • 61
  • 90
1

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).

v154c1
  • 1,698
  • 11
  • 19
  • You're right. It's as is in `configure`. `cat ./configure | grep AX_CHECK_COMPILE_FLAG` result is: `AX_CHECK_COMPILE_FLAG(-std=c++0x, CXXFLAGS="$CXXFLAGS -std=c++0x")` – sorush-r Dec 15 '12 at 07:20
  • Have you fixed this? If yes, how did you do it? – Qsiris Dec 20 '12 at 13:27
  • 2
    @soroush I fixed it using `CXXFLAGS="$CXXFLAGS -std=c++0x"` at the end of my configure.in (configure.ac) file, right before `AC_OUTPUT`. Otherwise the compile parameters will not be placed in the correct order. (in my case) – Qsiris Dec 27 '12 at 13:37
  • @Qsiris I want my configure script to check that platform supports C++11 or not. Brett's solution works fine, though I'm not satisfied yet. There should be a macro for that – sorush-r Dec 27 '12 at 13:42