Next: , Previous: , Up: Compilers and Preprocessors   [Contents][Index]


5.10.4 C++ Compiler Characteristics

Macro: AC_PROG_CXX ([compiler-search-list])

Determine a C++ compiler to use.

If either the environment variable CXX or the environment variable CCC is set, its value will be taken as the name of a C++ compiler. If both are set, CXX is preferred. If neither are set, search for a C++ compiler under a series of likely names, trying g++ and c++ first. Regardless, the output variable CXX is set to the chosen compiler.

If the optional first argument to the macro is used, it must be a whitespace-separated list of potential names for a C++ compiler, which overrides the built-in list.

If no C++ compiler can be found, as a last resort CXX is set to g++ (and subsequent tests will probably fail).

If the selected C++ compiler is found to be GNU C++ (regardless of its name), the shell variable GXX will be set to ‘yes’. If the shell variable CXXFLAGS was not already set, it is set to -g -O2 for the GNU C++ compiler (-O2 on systems where G++ does not accept -g), or -g for other compilers. CXXFLAGS is then made an output variable. You can override the default for CXXFLAGS by inserting a shell default assignment between AC_INIT and AC_PROG_CXX:

: ${CXXFLAGS="options"}

where options are the appropriate set of options to use by default. (It is important to use this construct rather than a normal assignment, so that CXXFLAGS can still be overridden by the person building the package. See Preset Output Variables.)

If necessary, options are added to CXX to enable support for ISO Standard C++ features with extensions, preferring the newest edition of the C++ standard that is supported. Currently the newest edition Autoconf knows how to detect support for is ISO C++ 2011. After calling this macro, you can check whether the C++ compiler has been set to accept standard C++ by inspecting the shell variable ac_prog_cc_stdc. Its value will be ‘cxx11’ or ‘cxx98’, respectively, if the C++ compiler has been set to use the 2011 or 1990 edition of the C++ standard, and ‘no’ if the compiler does not support compiling standard C++ at all.

The tests for standard conformance are not comprehensive. They test the value of __cplusplus and a representative sample of the language features added in each version of the C++ standard. They do not test the C++ standard library, because this can be extremely slow, and because the C++ compiler might be generating code for a “freestanding environment” (in which most of the C++ standard library is optional). If you need to know whether a particular C++ standard header exists, use AC_CHECK_HEADER.

None of the options that may be added to CXX by this macro enable strict conformance to the C++ standard. In particular, system-specific extensions are not disabled. (For example, for GNU C++, the -std=gnu++nn options may be used, but not the -std=c++nn options.)

Macro: AC_PROG_CXXCPP

Set output variable CXXCPP to a command that runs the C++ preprocessor. If ‘$CXX -E’ doesn’t work, tries cpp and /lib/cpp, in that order. Because of this fallback, CXXCPP may or may not set C++-specific predefined macros (such as __cplusplus).

It is portable to run CXXCPP only on files with a .c, .C, .cc, or .cpp extension.

Some preprocessors don’t indicate missing include files by the error status. For such preprocessors an internal variable is set that causes other macros to check the standard error from the preprocessor and consider the test failed if any warnings have been reported. However, it is not known whether such broken preprocessors exist for C++.

Macro: AC_PROG_CXX_C_O

Test whether the C++ compiler accepts the options -c and -o simultaneously, and define CXX_NO_MINUS_C_MINUS_O, if it does not.


Next: Objective C Compiler Characteristics, Previous: C Compiler Characteristics, Up: Compilers and Preprocessors   [Contents][Index]