如何在外部库中隐藏编译中的警告

Blu*_*unT 7 c++ makefile compilation c++11

我有一个main.cpp文件,只有这个代码:

#include <iostream>
#include "include/rapi/RApi.h"

using namespace std;

int main() {
    std::cout << "Test\n";
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我编译时,我想看到我的代码中的警告,但不是来自外部包含的文件.我以前能够实现这一点,但是我可能在编译标志中遗漏了一些内容,因为当我不想看到它们时,我一直在从包含的头文件中查找错误.

这是我的编译命令:

g++ -isystem include -pedantic -Wall -Wextra main.cpp -o main.o
Run Code Online (Sandbox Code Playgroud)

我想看看main.cpp中的警告和错误,但不是来自include文件夹中的文件.

我已经尝试过-isysteminclude -isysteminclude/rapi,将-isystem标志传递到标志的末尾,但无济于事.

我在这里错过了什么吗?

Mad*_*ist 4

您需要添加-isystem include到编译行,然后还在代码中使用:

#include "rapi/RApi.h"
Run Code Online (Sandbox Code Playgroud)

(不是include/rapi/RApi.h)。该-isystem选项仅将“系统标头”属性应用于使用该搜索路径查找的文件。如果您将完整路径放入,#include则 GCC 会直接查找该路径并且不使用该-isystem路径,因此不应用“系统标头”属性。

关于使用<>vs "",行为的确切差异本质上是实现定义的。无需猜测,只需看看各种SO问题和答案,比如这个