Configuring the GCC compiler switches in Qt, QtCreator, and QMake
C++QtC++11Qt CreatorC++ Problem Overview
I recently tried to use Qt Creator 1.3.2, Qt 4.6.2, and GCC 4.4.0 (32-bit version) on Windows 7 (64-bit) to compile an application using some of the experimental C++0x extensions and encountered the following (fatal) error:
> This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.
In my search for a solution, I came across the thread qmake and compiler flags?, and added the following to the .pro file:
CXXFLAGS += -std=c++0x
but that didn't seem to make a difference.
So, I expect there's some tag I need to add to the .pro (project) file, but I've never messed with the GCC compiler switches in Qt, QMake, and QtCreator before, and I am uncertain about the proper invokation / incantation. So, my question is how do you set GCC compiler switches when using QtCreator, QMake, and Qt?
C++ Solutions
Solution 1 - C++
It boils down to reading the manual. Instead of using CXXFLAGS
in the .pro file, you need to use QMAKE_CXXFLAGS
as in:
main.cpp:
#includeint main() { return 0; }
main.pro:
SOURCES += main.cpp QMAKE_CXXFLAGS += -std=c++0xSolution 2 - C++
You should use
CONFIG += c++11
to enable C++11 compiler flags automatically.
Look for .prf
files in your qt installation. I don't know where they might be on windows, but on my Linux installation they are under /opt/Qt/5.4/gcc_64/mkspecs/features
.
You might want to read the qmake documentation for that:
> qmake can be set up with extra configuration features that are > specified in feature (.prf) files. These extra features often provide > support for custom tools that are used during the build process. To > add a feature to the build process, append the feature name (the stem > of the feature filename) to the CONFIG variable.
You can add your own features.
Here is what I found on my system. CONFIG += name will enable the feature:
./android/android_deployment_settings.prf
./android/android.prf
./build_pass.prf
./c++11.prf
./c++14.prf
./cmake_functions.prf
./configure.prf
./create_cmake.prf
./ctest_testcase_common.prf
./ctest_testcase_installed.prf
./ctest_testcase.prf
./dbusadaptors.prf
./dbusinterfaces.prf
./declarative_debug.prf
./default_post.prf
./default_pre.prf
./designer_defines.prf
./device_config.prf
./egl.prf
./exceptions_off.prf
./exceptions.prf
./exclusive_builds_post.prf
./exclusive_builds.prf
./gcov.prf
./include_source_dir.prf
./incredibuild_xge.prf
./java.prf
./lex.prf
./link_ltcg.prf
./link_pkgconfig.prf
./ltcg.prf
./mac/default_post.prf
./mac/default_pre.prf
./mac/objective_c.prf
./mac/rez.prf
./mac/sdk.prf
./moc.prf
./no_debug_info.prf
./precompile_header.prf
./qfeatures.prf
./qlalr.prf
./qml1_module.prf
./qml1_plugin.prf
./qml_debug.prf
./qml_module.prf
./qml_plugin.prf
./qmltestcase.prf
./qpa/basicunixfontdatabase.prf
./qpa/genericunixfontdatabase.prf
./qt_android_deps.prf
./qt_app.prf
./qt_build_config.prf
./qt_build_paths.prf
./qt_common.prf
./qt_config.prf
./qt_docs.prf
./qt_docs_targets.prf
./qt_example_installs.prf
./qt_functions.prf
./qt_headersclean.prf
./qt_helper_lib.prf
./qt_installs.prf
./qt_module_headers.prf
./qt_module.prf
./qt_module_pris.prf
./qt_parts.prf
./qt_plugin.prf
./qt.prf
./qt_targets.prf
./qt_tool.prf
./resolve_config.prf
./resolve_target.prf
./resources.prf
./silent.prf
./simd.prf
./spec_post.prf
./spec_pre.prf
./testcase.prf
./testcase_targets.prf
./testcocoon.prf
./testlib_defines.prf
./uic.prf
./unix/bsymbolic_functions.prf
./unix/dylib.prf
./unix/hide_symbols.prf
./unix/largefile.prf
./unix/opengl.prf
./unix/openvg.prf
./unix/separate_debug_info.prf
./unix/thread.prf
./unix/x11inc.prf
./unix/x11lib.prf
./unix/x11.prf
./unix/x11sm.prf
./use_c_linker.prf
./vxworks.prf
./warn_off.prf
./warn_on.prf
./wayland-scanner.prf
./win32/console.prf
./win32/default_pre.prf
./win32/dumpcpp.prf
./win32/idcidl.prf
./win32/msvc_mp.prf
./win32/opengl.prf
./win32/openvg.prf
./win32/qt_config.prf
./win32/qt_dll.prf
./win32/rtti_off.prf
./win32/rtti.prf
./win32/stl_off.prf
./win32/stl.prf
./win32/windeployqt.prf
./win32/windows.prf
./winrt/console.prf
./winrt/font_deployment.prf
./winrt/package_manifest.prf
./yacc.prf
Solution 3 - C++
The only way that really works for me is to add it to QMAKE_CXXFLAGS
.
The CONFIG += c++11
does not add -std=c++11
to the compile command.