Autotools check for C++11
Asked Answered
E

2

23

I use AX_CXX_COMPILE_STDCXX_0X(can look on autoconf-archive) to check for c++11 capabilities of the compiler. It correctly determines that -std=c++0x required, but does not add it to CXXFLAGS. I took a look at the macro source and it actually checks but then restores previous flags.

What should I do to get CXXFLAGS set to be able to compile c++11 source?

Just adding -std=c++0x to AM_CXXFLAGS is not nice solution, because I'd like to put the burden of making the compiler compile in C++11 mode on the autoconf developers, not me.

Eugenaeugene answered 10/8, 2012 at 21:14 Comment(0)
S
31

What you're looking for has already been made as AX_CXX_COMPILE_STDCXX_11, part of autoconf-archive. It will add the required option to the environment (formerly through CXXFLAGS, now through CXX) and error out if no C++11 support is available.

Stylolite answered 10/8, 2012 at 22:59 Comment(10)
configure.ac:15: error: AC_LANG_ASSERT: current language is not C++: C ../../lib/autoconf/lang.m4:156: AC_LANG_ASSERT is expanded from... m4/ax_cxx_compile_stdcxx_11.m4:48: AX_CXX_COMPILE_STDCXX_11 is expanded from... configure.ac:15: the top level autom4te: /usr/bin/m4 failed with exit status: 1 aclocal: error: /usr/bin/autom4te failed with exit status: 1 autoreconf: aclocal failed with exit status: 1 I put it just after AC_PROG_CXX. What I do wrong?Eugenaeugene
Sorry for long comment. I found no way to format it. Well, I added AC_LANG([C++]) just before AX_CXX_COMPILE_STDCXX_11, but I assumed it is called by AC_PROG_CXX.Eugenaeugene
@illusionoflife AC_PROG_CXX shouldn't do that because it would mess up configure scripts that have both C and C++ checks. Most autoconf checks rely on C. Adding AC_LANG as you have is the right thing to do.Stylolite
How is this macro installed? Does it come with autoconf itself? If I add this macro to my configure.ac the -std compilerflags are not added. I can also only add the macro without any arguments (i.e. as AX_CXX_COMPILE_STDCXX_11() .. the documentation on autoconf-archive states that it should accept 2 parameters but when I try that it bails out with a syntax error when I run configure.Implacable
@Implacable Please be more specific than "a syntax error". :) Like most macros, this one should end up in your project's m4 directory, and your project should be set up to use that directory as the option argument to the -I option.Stylolite
I can't be a lot more specific: "./configure: line 2308: syntax error near unexpected token `ext,mandatory'" for instanceImplacable
question here: should ax_cxx_compile_stdcxx_11.m4 set CXXFLAGS (as it does) or AM_CXXFLAGS? The problem is that I cannot do a user-level setting of CXXFLAGS on the make line, for example: make CXXFLAGS="-g -O0 -Wall" fails because the -std=c++11 flag gets lost.Sher
@Sher The latest version doesn't clobber CXXFLAGS, it now clobbers CXX instead. I add CXX$1_FLAGS=$switch and AC_SUBST(CXX$1_FLAGS) to have it instead set e.g. CXX11_FLAGSService
To get it to work, I also installed autoconf-archive, which is where the macro 'lives', as far as I understand it.Broom
@Broom Right, that's why I linked to documentation from autoconf-archive, but it's good to mention it explicitly. Thanks for the comment.Stylolite
O
1

In general you can compile a simple code and set a variable based the outcome of your compilation

DIALECT="-std=c++14"
echo 'int main() {return 0;}' > ./log.cpp && $CXX -std=c++14 ./log.cpp || $DIALECT="no"

if test $DILAECT = no; then
    AC_MSG_ERROR([c++ compiler does not support c++14])
else
    echo $DILAECT
fi
Overtax answered 27/3, 2018 at 16:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.