I'm developping a software with C and C++ code. I've recently added some code in c++11 standard. In configure.ac I wrote:
for f in '-std=c++11' '-std=c++11 -stdlib=libc++'
do
AX_CHECK_COMPILE_FLAG([$f], [CXXFLAGS="$CXXFLAGS $f" stdpass=true], [], [], [])
${stdpass-false} && break
done
if ! "${stdpass-false}"; then
AC_MSG_ERROR([Unable to turn on C++11 mode with this compiler])
fi
With gcc I've no problem, everything goes well the option -std=c++11 is only applied to g++ and not on gcc. If I try to configure with:
CC=clang ./configure
I have the following error:
checking whether C compiler accepts -std=c++11... no
checking whether C compiler accepts -std=c++11 -stdlib=libc++... no
configure: error: Unable to turn on C++11 mode with this compiler
It's like if the option was applied on the C compiler and not only on clang++ (like it's done with gcc).
Can someone help me to figure out what I'm doing wrong.
OK, after some investigations I have the answer. First, in configure.ac I must set the language I use:
AC_LANG([C])
AC_LANG([C++])
Then, there is already an autoconf macro that checks for C++11 support in the C++ compiler: AX_CXX_COMPILE_STDCXX_11.
So, following this link: https://www.gnu.org/software/automake/manual/html_node/Local-Macros.html, I have to create a m4 folder and put the macro definition inside. The best way to proceed is to only download the more general ax_cxx_compile_stdcxx.m4 file (and not ax_cxx_compile_stdcxx_11.m4). So, always in configure.ac I write:
AC_CONFIG_MACRO_DIR([m4])
and
m4_include([m4/ax_cxx_compile_stdcxx.m4])
AX_CXX_COMPILE_STDCXX(11, noext, mandatory)
and Voilà. Everything is OK, at least on the machine I've tested.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With