在 Qt 中添加额外的编译器选项
在 Qt 中哪里可以指定额外的编译器选项?例如 -std=c++0x?
Where in Qt can I specify additional compiler options? Like for example -std=c++0x?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试添加
到您的 .pro 文件中。
然而,这不应该在 Qt 5 中用于启用特定的 C++ 标准。相反,可以使用
CONFIG
变量中的c++11
或c++14
来执行此操作。它将启用 GNU 扩展 (-std=gnu++11),但如果不需要,还可以添加strict_c++
如果您想禁用它们。例如,这应该将-std=c++11
传递给编译器:You can try adding
to your .pro file.
However, this should not be used in Qt 5 for enabling specific c++ standard. Instead,
c++11
orc++14
inCONFIG
variable to do that. It will enable GNU extensions (-std=gnu++11), but if that is unwanted, also addstrict_c++
if you want to disable those. For example, this should pass-std=c++11
to the compiler:在您的 .pro 文件中,您可以添加:
我认为规范的
qmake.conf
中的每个变量都可以这样更改。例如,win32-g++ 规范除其他变量外还具有以下这些:
In your .pro file, you could add:
I think every variable in the spec's
qmake.conf
can be altered like that.For example, the win32-g++ spec has, among other variables, these:
QT 处理编译器选项的方式是通过 .pro 文件。如果可以的话,这是一把双刃剑。它创建了一个很好的抽象,特别是在编译大型项目时。问题是您必须查找或记住如何添加标志。对于 C++0X,您必须将以下标志添加到您的 .pro 文件中:
幸运的是,如果您使用 QtCreator,您需要的大多数标志都会自动添加。
The way QT deals with compiler options is through the .pro file. It is a double edged sword if I may. It creates a nice abstraction, especially when compiling large projects. The problem is that you have to either look up or memorize how to add the flag. In the case of C++0X, you have to add the following flag to your .pro file:
Fortunately most of the flags that you need are automatically added if you use QtCreator.