C++ 在 Qt Creator 中,我在哪里将参数传递给编译器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7980499/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 17:50:02  来源:igfitidea点击:

Where in Qt Creator do I pass arguments to a compiler?

c++qtqt-creator

提问by smallB

Where in Qt Creator do I pass arguments to a compiler?
It isn't really that obvious.

在 Qt Creator 中,我在哪里将参数传递给编译器?
这真的不是那么明显。

回答by mbx

Depending on your build system it's either in your qmake project file(.pro, standard for new projects) or in one of the CMakefiles (CMakeLists.txt, used by KDE and several other projects).

根据您的构建系统,它位于您的qmake 项目文件(.pro,新项目的标准)或CMake文件之一(CMakeLists.txt,由 KDE 和其他几个项目使用)。

Using .pro:

使用 .pro:

QMAKE_CXXFLAGS += -O2

Using CMake:

使用 CMake:

set( CMAKE_CXX_FLAGS "-g -Wall")

回答by Frank Osterfeld

To add compiler flags, open your .pro file and add a line like this:

要添加编译器标志,请打开您的 .pro 文件并添加如下一行:

QMAKE_CXXFLAGS += -std=c++0x

For standard flags like debug vs. release etc. you should try to use the predefined qmake options (see QMake documentation) for the sake of platform and compiler-independency, as QMake will map them to the compiler-specific flags.

对于像调试与发布等标准标志,为了平台和编译器独立性,您应该尝试使用预定义的 qmake 选项(请参阅 QMake 文档),因为 QMake 会将它们映射到特定于编译器的标志。

回答by lolo67

If your intention is to precompile some source code you can do like this:

如果您打算预编译一些源代码,您可以这样做:

/A/ In your .pro file you can add a line like this:

/A/ 在您的 .pro 文件中,您可以添加如下一行:

DEFINES += HOPLA

/B/ In you .cpp or .h file you can use it like this

/B/ 在您的 .cpp 或 .h 文件中,您可以像这样使用它

#ifdef HOPLA
// Do something
#else
// Do something different
#endif

回答by lalitm

for C projects, add the following line in .pro file

对于 C 项目,在 .pro 文件中添加以下行

QMAKE_CFLAGS += -std=c99

回答by Bayron Jonathan Vazquez

in the .pro file you can add variables which modify the make behavior for example, if you try to execute the following command:

在 .pro 文件中,您可以添加修改 make 行为的变量,例如,如果您尝试执行以下命令:

g++ -Wall -I/usr/include/cppconn -o exe main.cpp -L/usr/lib -lmysqlcppconn

you must add the following lines in the .pro file

您必须在 .pro 文件中添加以下几行

INCLUDEPATH += /usr/include/cppconn
LIBS += -L/usr/lib -lmysqlcppconn

Check the image below. enter image description here

检查下面的图像。 在此处输入图片说明

For more information on the available variables that QT IDE uses, you can visit the following link where they explain in more detail each one. Qt Documentation: Variables

有关 QT IDE 使用的可用变量的更多信息,您可以访问以下链接,其中对每个变量进行了更详细的解释。Qt 文档:变量

回答by Basile Starynkevitch

In your Qmake project fileprobably

在您的Qmake 项目文件中可能