在 Qt Creator 中哪里可以将参数传递给编译器?
在 Qt Creator 中哪里可以将参数传递给编译器?
其实并不是那么明显。
Where in Qt Creator do I pass arguments to a compiler?
It isn't really that obvious.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
根据您的构建系统,它位于您的 qmake 项目文件< /a>(.pro,新项目的标准)或 CMake 文件(CMakeLists.txt,由 KDE 和其他几个项目使用)。
使用 .pro:
使用 CMake:
Depending on your build system it's either in your qmake project file(.pro, standard for new projects) or in one of the CMake files (CMakeLists.txt, used by KDE and several other projects).
Using .pro:
Using CMake:
要添加编译器标志,请打开 .pro 文件并添加如下行:
对于标准标志(如调试与发布等),为了平台和编译器独立性,您应该尝试使用预定义的 qmake 选项(请参阅 QMake 文档) ,因为 QMake 会将它们映射到编译器特定的标志。
To add compiler flags, open your .pro file and add a line like this:
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.
如果您的目的是预编译一些源代码,您可以这样做:
/A/ 在您的 .pro 文件中,您可以添加如下行:
/B/ 在您的 .cpp 或 .h 文件中,您可以像这样使用它
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:
/B/ In you .cpp or .h file you can use it like this
对于 C 项目,在 .pro 文件中添加以下行
for C projects, add the following line in .pro file
作为选定的答案点,对于基于 CMake 的项目,您可以编辑
CMakeLists.txt
并设置编译器的标志,对于这种情况,我有一个关于如何在 QtCreator 上添加标志的图片演示/CMake.我想添加“-pedantic”标志,它会警告扩展,而不会在执行程序时抛出错误,下面是如何在使用 QtCreator 时在 CMake 上启用编译器标志的图解示例:
了解更多背景信息:
As the elected answer points, for CMake based projects, you can edit the
CMakeLists.txt
and set the flags for the compiler, and for this case, I have a pictorial demonstration on how to add flags on QtCreator/CMake.I wanted to add the '-pedantic' flag, which warns about extensions, without throwing errors while executing the program, and here's pictorial example of how to enable compiler flags on CMake while using QtCreator:
For more context:
在 .pro 文件中,您可以添加修改 make 行为的变量,例如,如果您尝试执行以下命令:
您必须在 .pro 文件中添加以下行
检查下图。
有关 QT IDE 使用的可用变量的更多信息,您可以访问以下链接,其中对每个变量进行了更详细的解释。 Qt 文档:变量
in the .pro file you can add variables which modify the make behavior for example, if you try to execute the following command:
you must add the following lines in the .pro file
Check the image below.
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