How to eliminate external lib/third party warnings in GCC [duplicate]

本小妞迷上赌 提交于 2019-11-30 03:03:39
Dummy00001

I presume you are talking about the warnings coming from the 3rd party library headers.

The GCC specific solution would be to create another wrapper header file which has essentially the two lines:

#pragma GCC system_header
#include "real_3rd_party_header.h"

And use the wrapper instead of the original 3rd party header.

Check another SO response detailing the pragma. It essentially tells GCC that this (with recursively included files) is a system header, and no warning messages should be generated.

Otherwise, I'm not aware how one can disable warnings coming from the 3rd party code. Except by the brute force of course: in the build system configure the files to be built with warnings off.

Use -isystem Example:

gcc -I./src/ -isystem /usr/include/boost/ -c file.c -o obj/file.o

With -isystem NO warning about boost :D

If you're using CMake, you can achieve this by adding SYSTEM to include_directories:

include_directories(SYSTEM "${LIB_DIR}/Include")
                    ^^^^^^

http://www.artima.com/cppsource/codestandards.html

Example 1: A third-party header file. A library header file that you cannot change could contain a construct that causes (probably benign) warnings. Then wrap the file with your own version that #includes the original header and selectively turns off the noisy warnings for that scope only, and then #include your wrapper throughout the rest of your project.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!