C++14 support in QtCreator with Clang

夙愿已清 提交于 2019-12-05 00:00:53

问题


How can I enable C++14 support in QtCreator 3.3 using Clang 3.5? I have added a Clang kit and I have added CONFIG += c++14 in my project file. However when using e.g. return type deduction I get the following error:

error: 'auto' return without trailing return type; deduced return types are a C++1y extension


回答1:


you can use CONFIG += c++14 in .pro file with Qt5.5

but there is a bug with clang, so we need to modify the Qt/5.5/clang_64/mkspecs/features/c++14.prf file, add this code beforeinclude(c++11.prf) :

contains(QMAKE_LFLAGS_CXX11, -stdlib=libc++) {
    QMAKE_CXXFLAGS_CXX11 += -stdlib=libc++
}



回答2:


I had to go to the Makefile in the build folder and manually replace -std=c++11 with -std=c++14.

Thankfully the Makefile is only written once when you add the kit to the project. I only had to do this once and could build in QtCreator as often as I want.

So now I can use a Clang kit to use all the new c++14 features. As a bonus, I can also use all the c++17 features if I manually set -std=c++1z in the Makefile. Sweet!



来源:https://stackoverflow.com/questions/27858273/c14-support-in-qtcreator-with-clang

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!