当-pedantic开启时,在GCC中抑制"额外';'"错误

Rom*_*nko 6 gcc compiler-errors g++

我正在使用-pedanticflag 构建我的程序,这会导致extra ';'错误(因为第三方标头使用了一些不一致的宏;当-pedantic关闭时不会显示错误).我真的不想-pedantic关闭,我也不想编辑标题.有没有办法抑制这个确切的错误?像-Wno-annoying-semicolon-error编译器开关或什么?

Shi*_*hah 7

您可以像这样抑制外部标题的迂腐警告:

//save compiler switches
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"

//Bad headers with problem goes here
#include <ros/ros.h>
#include <sensor_msgs/LaserScan.h>

//restore compiler switches
#pragma GCC diagnostic pop
Run Code Online (Sandbox Code Playgroud)


ide*_*n42 5

在传递包含路径时使用-isystem而不是-I,则 GCC 不会警告您有关系统标头的信息。

对于您维护的任何标题,只需编辑它们。


F'x*_*F'x 0

解决方法是删除-pedantic. 对于这种情况,没有其他方法可以解决。