简体   繁体   English

OSX上Qt5 / QtCreator 3.0.1中的C ++ 11

[英]C++11 in Qt5 / QtCreator 3.0.1 on OSX

Just downloaded and installed Qt5 on OSX 10.9.2. 刚刚在OSX 10.9.2上下载并安装了Qt5。

When trying to compile some C++11 code using the clang run kit, I get a failure when I try to include cstdint; 当尝试使用clang run kit编译一些C ++ 11代码时,尝试包含cstdint时失败。

fatal error: 'cstdint' file not found

After a lot of googling, it seems that c++11 is not 'enabled' by default which triggers this error. 经过大量的搜寻后,默认情况下似乎未启用c ++ 11并触发了此错误。 It further seems that the way to enable c++11 has changed in Qt5. 进一步看来,启用C ++ 11的方法在Qt5中已更改。 It should be as simple as adding CONFIG+=c++11 in "Projects -> Build & Run -> Build Steps -> Additional arguments" if I understand it correctly. 如果我理解正确的话,它应该就像在“项目->构建并运行->构建步骤->其他参数”中添加CONFIG + = c ++ 11一样简单。

However this makes no difference whatsoever. 但是,这没有任何区别。

So; 所以; anyone knows how to enable c++11 using QtCreator with the clang kit? 有谁知道如何使用带有clang套件的QtCreator启用c ++ 11?

About QtCreator gives me the following information: QtCreator 3.0.1 Based on Qt 5.2.1 (Clang 5.0 (Apple), 64 bit) 关于QtCreator为我提供了以下信息:基于Qt 5.2.1的QtCreator 3.0.1(Clang 5.0(Apple),64位)

The compiler output is as follows: 编译器输出如下:

14:25:23: Running steps for project shelly...
14:25:23: Starting: "/Users/m/Qt5.2.1/5.2.1/clang_64/bin/qmake" /Volumes/files/Programmering/shelly/shelly.pro -r -spec macx-clang CONFIG+=debug CONFIG+=x86_64 CONFIG+=declarative_debug CONFIG+=qml_debug CONFIG+=c++11
14:25:23: The process "/Users/m/Qt5.2.1/5.2.1/clang_64/bin/qmake" exited normally.
14:25:23: Starting: "/usr/bin/make" 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -c -pipe -g -gdwarf-2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.7 -Wall -W -fPIE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/Users/m/Qt5.2.1/5.2.1/clang_64/mkspecs/macx-clang -I../shelly -I/Users/m/Qt5.2.1/5.2.1/clang_64/lib/QtOpenGL.framework/Versions/5/Headers -I/Users/m/Qt5.2.1/5.2.1/clang_64/lib/QtWidgets.framework/Versions/5/Headers -I/Users/m/Qt5.2.1/5.2.1/clang_64/lib/QtGui.framework/Versions/5/Headers -I/Users/m/Qt5.2.1/5.2.1/clang_64/lib/QtCore.framework/Versions/5/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/AGL.framework/Headers -I. -I. -F/Users/m/Qt5.2.1/5.2.1/clang_64/lib -o datainterval.o ../shelly/core/datainterval.c++
In file included from ../shelly/core/datainterval.c++:5:
In file included from ../shelly/core/datainterval.h++:9:
../shelly/core/datatime.h++:9:10: fatal error: 'cstdint' file not found
#include <cstdint> // GPL w/runtime exception
         ^
1 error generated.
make: *** [datainterval.o] Error 1
14:25:24: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project shelly (kit: Desktop Qt 5.2.1 clang 64bit)
When executing step 'Make'
14:25:24: Elapsed time: 00:01.

Update: 更新:

Have made an 'minimal recreate' of my problem; 使我的问题“最小化”了;

  1. Create a new project, a “Qt Widgets Application”. 创建一个新项目,一个“ Qt Widgets Application”。
  2. Leave everything at its defaults except for the path. 将所有内容保留为默认值(路径除外)。
  3. In the created file mainwindow.c++, add the cstdint include statement: 在创建的文件mainwindow.c ++中,添加cstdint include语句:
  4. Try to build it (it fails as above) 尝试构建它(如上所述失败)
  5. Add in “Projects” -> “Build & Run” -> “Build Steps” -> “Additional arguments” 在“项目”->“构建并运行”->“构建步骤”->“其他参数”中添加

    CONFIG+=c++11 CONFIG + = C ++ 11

The “Effective qmake call” line then reads 然后,“有效的qmake调用”行显示为

qmake /Users/m/Documents/ProgrammeringOSX/testC11/testC11.pro -r -spec macx-clang CONFIG+=debug CONFIG+=x86_64 CONFIG+=declarative_debug CONFIG+=qml_debug CONFIG+=c++11

…and the error is still there. …错误仍然存​​在。

:( :(

I have the same setup as you, and have used c++11 features after updating the project .pro file with the following line: 我的设置与您相同,并在使用以下代码行更新项目.pro文件后使用了c ++ 11功能:

CONFIG += c++11

However, I think your solution should accomplish the same thing, so it may be an external configuration issue. 但是,我认为您的解决方案应该完成同样的事情,因此这可能是外部配置问题。 I wasn't able to reproduce the error when I included the header file. 当包含头文件时,我无法重现该错误。

Ok, 好,

I seem to have “fixed” it… I got to the point that I was randomly changing parameters just to see what effect it had and all of a sudden this did it: 我似乎已经“修复”了它……我发现我在随机更改参数只是为了看看它产生了什么效果,突然之间做到了:

QMAKE_MACOSX_DEPLOYMENT_TARGET=10.9

(doesn't matter if I set it in the .pro file or in the GUI) (无论是在.pro文件中还是在GUI中进行设置都没关系)

If I added CONFIG+=c++11, the target was set to 10.7, without it 10.6, so this forces it to 10.9 (tried 10.8 as well, but nope; 10.9 it is). 如果我添加了CONFIG + = c ++ 11,则将目标设置为10.7,不将其设置为10.6,因此这将其强制设置为10.9(也尝试了10.8,但不,是10.9)。

A funny thing is that I do not need to add CONFIG+=c++11 in the “minimum recreation” version… I guess I will get to that point if I actually add any C++11 code. 有趣的是,我不需要在“最低限度的娱乐”版本中添加CONFIG + = c ++ 11 ...我想,如果我实际上添加任何C ++ 11代码,我都会明白这一点。 But baby steps, baby steps! 但是婴儿的脚步,婴儿的脚步!

Another funny thing is that when I changed the target to 10.9, THEN my bogus QMAKE_CXXFLAGS parameters were added and the clang call failed (I guess it heeded my 'pleaseFailNow' parameter). 另一个有趣的事情是,当我将目标更改为10.9时,然后添加了我的虚假QMAKE_CXXFLAGS参数,并且clang调用失败(我猜它遵循了我的“ pleaseFailNow”参数)。

Thank you for your help! 谢谢您的帮助!

Cheers / Daniel 干杯/丹尼尔

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM