I am trying to use autoconf to create a configure script. However, some of the headers I want to check for require additional compiler flags (e.g. c++11). I can get partly there with the answer here where the relevant lines look like this in the configure.ac file.


but the std=gnu++11 flag isn't passed to the preprocessing step of AC_CHECK_HEADERS where I end up with the strange result where it is usable but not present:

checking CL/cl2.hpp usability... yes
checking CL/cl2.hpp presence... no

Looking in the config.log shows the following lines:

configure:3423: checking CL/cl2.hpp presence
configure:3423: g++ -E conftest.cpp
In file included from conftest.cpp:19:0
/usr/include/CL/cl2.hpp:442:2: error #error Visual studio 2013 or another C++11-supported compiler required

where I can clearly see that the C++ flag is not being used. How can I have compiler flags be used in these preprocessor steps?


I can manually get around this by setting the CXXCPP manually when running configure but I'd like it to run without the end user needing to know this.

./configure CXXCPP="g++ -E -std=gnu++11"

2 Answers 2


The current solution I have come up with is to manually add:

CXXCPP="g++ -E -std=gnu++11"

directly to the configure.ac file. I would be happy to hear any additional answers.

  • This is the same thing I do, when adding compiler flags, in my own autoconf scripts. However, before doing so, I have autoconf macros/checks try to compile a simple program, to ensure that the compiler does support flag; different compilers (and versions of compilers) may or may not support the flags, over time.
    – Castaglia
    Commented Feb 19, 2016 at 0:59

I had to run configure like this:

./configure CCFLAGS="-std=c++11" CXXFLAGS="-std=c++11" CXXCPP="-std=c++11"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .