How to hide warnings in compilation from external libraries

I have a main.cpp file that only has this code:

#include <iostream> #include "include/rapi/RApi.h" using namespace std; int main() { std::cout << "Test\n"; return 0; } 

When I compile, I want to see warnings from my code, but not from external files. I have been able to achieve this in the past, but there may be something missing from the compilation flags, as I continue to troubleshoot errors from the included header file when I don't want to see them.

This is my compilation command:

 g++ -isystem include -pedantic -Wall -Wextra main.cpp -o main.o 

I want to see warnings and errors from main.cpp, but not from files in the include folder.

I tried -isysteminclude -isysteminclude/rapi , passing -isystem to the end of the flags, but to no avail.

Did I miss something?

+7
c ++ c ++ 11 compilation makefile
source share
2 answers

You need to add -isystem include to your compilation line, then ALSO use in your code:

 #include "rapi/RApi.h" 

(not include/rapi/RApi.h ). The -isystem option applies the "system header" attribute to files that are viewed using this search path. If you put the full path in #include , then GCC will look for the path directly and will not use the -isystem path, so the "system header" attribute is not applied.

Regarding the use of <> vs "" exact difference in behavior is essentially determined by the implementation. No need to guess, just look at various questions and answers, for example this one .

+4
source share
 #include <iostream> #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wall" #include "include/rapi/RApi.h" #pragma GCC diagnostic pop int main() { std::cout << "Test\n"; return 0; } 
+2
source share

All Articles