C++ Qt - 如何添加“-std=c++11"到由 qmake 生成的 makefile? [英] C++ Qt - How to add "-std=c++11" to the makefile which is generated by qmake?

查看:101
本文介绍了C++ Qt - 如何添加“-std=c++11"到由 qmake 生成的 makefile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 Qt 开发一个程序.它的 makefile 是从 .pro 文件自动生成的.我需要使用一些需要为 g++ 设置 -std=c++11 标志的代码.我应该在 .pro 的什么地方添加这个标志?(仅更改 Makefile 不起作用,因为每次我构建项目时它都会被新生成的覆盖).

I'm developing a program in Qt. Its makefile is generated automatically from the .pro file. I need to use some code which need the -std=c++11 flag to be set up for g++. Where in .pro should I add this flag? (changing only the Makefile won't work since it gets overwritten by the newly generated one, each time I build the project).

推荐答案

您可能会发现插入特定标志(您提到的)很诱人

You may find it tempting to insert the specific flag (which you mention)

QMAKE_CXXFLAGS += -std=c++11

在您的 .pro 文件中,但这将仅代表您插入该标志.

in your .pro file, but this will insert just that flag on your behalf.

这还不够.正确的方法是插入

That's insufficient. The right way is to insert instead

CONFIG += c++11

在您的 .pro 文件中.qmake 然后进行两到三个必要的更改:

in your .pro file. Two or three necessary changes are then made by qmake:

  1. -std=c++11 已插入.
  2. -stdlib=libc++ 已插入.
  3. 如果您使用的是 Mac,-mmacosx-version-min=10.6 将变为 -mmacosx-version-min=10.7.(也许在其他操作系统或操作系统版本上需要进行一些类似的更改.)
  1. -std=c++11 is inserted.
  2. -stdlib=libc++ is inserted.
  3. If you're on a Mac, -mmacosx-version-min=10.6 becomes -mmacosx-version-min=10.7. (Perhaps some similar change is necessary on other OSes or OS versions.)

(12.)

这篇关于C++ Qt - 如何添加“-std=c++11"到由 qmake 生成的 makefile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆