Linux Qt pro文件的CXXFLAGS修改?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5837106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CXXFLAGS modification of Qt pro file?
提问by Brian Stinar
Possible Duplicate:
Configuring the GCC compiler switches in Qt, QtCreator, and QMake
I would like to use -O1
instead of -O2
in my makefile (CFLAGS
and CXXFLAGS
) for my Linux build. My understanding of how these makefiles are generated based on the .pro file is somewhat lacking. This is because the version of Qt combined with the version of G++ I am using has instabilities when -O2
is present.
我想在我的 Linux 构建中使用-O1
而不是-O2
在我的 makefile(CFLAGS
和CXXFLAGS
)中。我对如何基于 .pro 文件生成这些 makefile 的理解有些欠缺。这是因为 Qt 版本与我正在使用的 G++ 版本相结合时-O2
存在不稳定性。
Presently, I am running a replacement script, after I run qmake, which does this:
目前,在运行 qmake 后,我正在运行替换脚本,它执行以下操作:
sed -i 's/\-O2/\-O1/g' AllProjects/Makefile.Release
This is a ghetto solution. A much better solution would be to modify the .pro file somehow to pass along these directives. I am not sure how CFLAGS
and CXXFLAGS
are being generated though.
这是一个贫民窟解决方案。更好的解决方案是以某种方式修改 .pro 文件以传递这些指令。我不确定如何CFLAGS
以及CXXFLAGS
正在生成。
I have tried passing a
我试过通过一个
linux-g++-{
CFLAGS += -O1
CXXFLAGS += -O1
CONFIG += -O1
}
which did not work.
这不起作用。
采纳答案by Evan Teran
You were very close. What you want is:
你非常接近。你想要的是:
QMAKE_CXXFLAGS += -O1
QMAKE_CXXFLAGS += -O1
If you would like to apply flags to just the release build, then you can use this:
如果您只想将标志应用于发布版本,那么您可以使用:
QMAKE_CXXFLAGS_RELEASE += -O1
QMAKE_CXXFLAGS_RELEASE += -O1
You also probably want to change your condition to be a little more flexible. In summary, something like this:
您可能还希望将您的条件更改为更灵活一些。总之,是这样的:
*-g++* {
QMAKE_CXXFLAGS += -O1
}
More in the documentation here: http://qt-project.org/doc/qt-5.0/qtdoc/qmake-variable-reference.html#qmake-cxxflags
更多文档在这里:http: //qt-project.org/doc/qt-5.0/qtdoc/qmake-variable-reference.html#qmake-cxxflags