首页 文章

在Qt,QtCreator和QMake中配置GCC编译器

提问于
浏览
72

我最近尝试在Windows 7(64位)上使用Qt Creator 1.3.2,Qt 4.6.2和GCC 4.4.0(32位版本)来编译使用某些实验性C 0x扩展的应用程序并遇到以下问题(致命错误:

此文件需要编译器和库支持即将推出的ISO C标准C 0x . 此支持目前是实验性的,必须使用-std = c 0x或-std = gnu 0x编译器选项启用 .

在我搜索解决方案时,我遇到了线程qmake and compiler flags?,并将以下内容添加到.pro文件中:

CXXFLAGS += -std=c++0x

但这似乎没有什么区别 .

所以,我希望有一些标签需要添加到.pro(项目)文件中,但我以前从未弄过Qt,QMake和QtCreator中的GCC编译器开关,我不确定正确的调用/咒语 . 所以,我的问题是如何在使用QtCreator,QMake和Qt时设置GCC编译器开关?

3 回答

  • 5

    归结为阅读manual . 而不是在.pro文件中使用 CXXFLAGS ,您需要使用 QMAKE_CXXFLAGS ,如下所示:

    main.cpp中:

    #include <cinttypes>
    
    int main() { return 0; }
    

    main.pro:

    SOURCES += main.cpp
    QMAKE_CXXFLAGS += -std=c++0x
    
  • 103

    你应该用

    CONFIG += c++11
    

    自动启用C 11编译器标志 .

    在qt安装中查找 .prf 文件 . 我不知道它们在Windows上的位置,但在我的Linux安装中,它们位于 /opt/Qt/5.4/gcc_64/mkspecs/features 之下 .

    您可能想要阅读qmake documentation

    可以使用功能(.prf)文件中指定的额外配置功能设置qmake . 这些额外功能通常为构建过程中使用的自定义工具提供支持 . 要向构建过程添加功能,请将功能名称(功能文件名的主干)附加到CONFIG变量 .

    你可以add your own features .

    这是我在我的系统上找到的 . CONFIG = name将启用该功能:

    ./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
    
  • 3

    真正适用于我的唯一方法是将其添加到 QMAKE_CXXFLAGS .

    编译命令的 CONFIG += c++11 does not add -std=c++11 .

相关问题