使用 qmake/gcc 有条件地禁用警告?
我参与了一个用 Qt 编写并在 Linux 上使用 qmake 和 gcc 构建的软件项目。 我们必须链接到质量相当低并且发出大量警告的第三方库。 我想在我们的源代码上使用 -W -Wall,但将 -w 传递给讨厌的第三方库,以保持控制台没有噪音和混乱,这样我们就可以专注于我们的代码质量。
在qmake中,有没有办法有条件地将CFLAGS/CXXFLAGS添加到某些文件和库?
I am involved with a software project written in Qt and built with qmake and gcc on Linux. We have to link to a third-party library that is of fairly low quality and spews tons of warnings. I would like to use -W -Wall on our source code, but pass -w to the nasty third-party library to keep the console free of noise and clutter so we can focus on our code quality.
In qmake, is there a way to conditionally add CFLAGS/CXXFLAGS to certain files and libraries?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
乔纳森,我认为问题在于您的源文件包含来自第三方库的头文件,并且您想关闭后者的警告。
凯文,我认为你可以使用编译指示来控制警告: gcc 诊断 pragmas
您可以在 3rd 方库的任何 #includes 之前和之后添加这些内容。
Jonathan, I think the problem is where your source files are including header files from 3rd party libraries, and you want to switch off the warnings for the latter.
Kevin, i think you can use pragmas to control warnings : gcc diagnostic pragmas
You could add these before and after any #includes for 3rd party libs.
如果您使用 -isystem 包含您的库会怎样?
在项目文件中,例如:
What if you include your library using -isystem.
In the project file e.g.:
通常,您会在与自己的代码不同的目录中构建第三方库,因此您将拥有不同的 makefile,因此您可以为该编译放置一组不同的标志。
如果您将第三方库代码与您自己的代码混合在一起,那么您就会陷入维护噩梦。
Normally, you'd build the third-party library in a separate directory from your own code, so you would have a different makefile for it, so you could put a different set of flags for that compilation.
If you've mixed the third-party library code with your own code, you have set yourself up for a maintenance nightmare.
凯文,
应该做
(如果您愿意,请使用 CONFIG+=release...)
Kevin,
should do
(use CONFIG+=release if you wish...)
添加包含目录
正如 Martin 所写,通过抑制相应标头中的警告来 。 无需禁用项目(甚至项目范围内)的任何源文件的警告,也无需弄乱#pragmas 或包装文件。
请注意,如果您使用 QtCreator,您仍然(即另外)希望将目录添加到 INCLUDEPATH 中,以便索引器拾取标头。
As Martin wrote adding the include directory via
suppresses warnings just in the respective headers. No need to disable warnings for any source files of your project (or even project-wide) or mess with #pragmas or wrappers files.
Note that if you're using QtCreator you'll still (i.e. additionally) want add the directory to
INCLUDEPATH
so the indexer picks up the headers.