1

I have the following line in autoconf:

AX_CHECK_COMPILE_FLAG([-std=c++0x], [CXXFLAGS="$CXXFLAGS -std=c++0x"], AC_MSG_ERROR([Need C++11 support]))

aclocal, autoconf and automake -a -c go smoothly.

However, when I run configure, I get the error:

./configure: line 2142: syntax error near unexpected token `-std=c++0x,'
./configure: line 2142: `AX_CHECK_COMPILE_FLAG(-std=c++0x, CXXFLAGS="$CXXFLAGS -std=c++0x", as_fn_error $? "Need C++11 support" "$LINENO" 5)'

Any ideas why?

EDIT: This seems to be different than the other questions, because

   AX_CHECK_COMPILE_FLAG(-std=c++0x)

by itself works...

EDIT:

Here is a full configure.ac

# initial information about the project
AC_INIT([myproject],[0.1],[project@gmail.com])

# check if the source folder is available
AC_CONFIG_SRCDIR([src/main.cpp])

# check for C++ preprocessor and compiler
CXXFLAGS="$CXXFLAGS -std=c++0x"
CXXFLAGS="$CXXFLAGS -O3"

AX_CHECK_COMPILE_FLAG([-std=c++0x], [CXXFLAGS="$CXXFLAGS -std=c++0x"], AC_MSG_ERROR([Need C++11 support]))

AC_PROG_CXXCPP
AC_PROG_CXX

AC_PROG_CC

# automake initialization (mandatory) including a check for automake API version >= 1.9
AM_INIT_AUTOMAKE([1.9])


# use the C++ compiler for the following checks
AC_LANG([C++])

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([string])
AC_CHECK_HEADERS([iostream])

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

# distribute additional compiler and linker flags among Makefiles
# --> set and change these variables instead of CXXFLAGS or LDFLAGS (for user only)
AC_SUBST([AM_CXXFLAGS])
AC_SUBST([AM_LDFLAGS])

# files to generate via autotools (prepare .am or .in source files)
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([src/Makefile])

# finally this generates the Makefiles etc. for the build
AC_OUTPUT
kloop
  • 4,537
  • 13
  • 42
  • 66
  • Possible duplicate of [autotools syntax error with ax\_check\_compile\_flag](https://stackoverflow.com/questions/30412576/autotools-syntax-error-with-ax-check-compile-flag) – ldav1s Jun 17 '17 at 05:59
  • Your `configure.ac` fails for me in the manner you describe when the `ax_check_compile_flag.m4` is not installed in `AC_CONFIG_MACRO_DIR`. Does not error for me when `ax_check_compile_flag.m4` is installed in `AC_CONFIG_MACRO_DIR`. Now convinced it's a duplicate. – ldav1s Jun 19 '17 at 13:48
  • BTW, automake 1.9 is like a decade old. You should set `AM_INIT_AUTOMAKE` to something more recent. – ldav1s Jun 19 '17 at 13:55

1 Answers1

0

That does not seem likely that it's a not the same, as if you do have AX_CHECK_COMPILE_FLAG defined in your autoconf search corpus, you would not even find a reference to it in the configure file at all.

But, you also have multiple spaces in front of the second example you give, which suggests me that you possibly have this in a conditional block, or following another macro or conditional block. Any other undefined macro in the configure.ac file may cause autoconf to emit a macro as literal, rather than expanding it as you expect it to. I would suggest you post a full, reduced configure.ac that shows the behaviour, rather than just one line.

Diego Elio Pettenò
  • 3,152
  • 12
  • 15