相关疑难解决方法(0)

如何禁用特定包含文件的警告?

我想对特定包含文件直接或间接包含的所有文件禁用特定警告.例如,我想禁用警告"你正在为字符串文字指定一个字符串文字*",包括a所包含的文件所包含的所有文件或文件#include <bar/*>(在我的情况下,明星意味着"任何东西可能在这里").

原因是,我必须编程的一些人不能使用"const",所以最后我得到很多关于特定字符串文字滥用的警告.我想忽略来自他们代码的成千上万的警告,所以我可以专注于我自己的代码中的错误并修复它们.

我使用的是英特尔C++和GCC.我的一些伙伴使用clang,所以我很乐意听到解决方案.

c++ suppress-warnings

68
推荐指数
4
解决办法
3万
查看次数

如何在GCC中消除外部lib /第三方警告

在我正在进行的软件项目中,我们使用了某些第三方库,遗憾的是,这些库产生了恼人的gcc警告.我们正在努力清除所有警告代码,并希望在GCC中启用treat-warnings-as-errors(-Werror)标志.有没有办法让这些我们无法修复的第三方生成的警告消失?

c++ gcc include suppress-warnings gcc-warning

24
推荐指数
3
解决办法
8039
查看次数

在GCC中抑制-Wunknown-pragmas警告

我试图忽略来自某些第三方头文件的警告,如下所示:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wreorder"

#include <some_3rd_party_header.h>

#pragma GCC diagnostic pop
Run Code Online (Sandbox Code Playgroud)

这种方法似乎总体上起作用,但不适用于未知的pragma警告(我仍然得到它们).

为什么它适用于其他警告但不适用于此警告?谁能证实这种行为?

我使用的是G ++(版本4.7.1)与-Wall-std=c++0xDebian的下.

gcc warnings pragma suppress-warnings

21
推荐指数
1
解决办法
9742
查看次数

如何在GCC中使用pragma指令禁用所有警告

我正在寻找一种方法来抑制我可能通过pragma指令获得的所有可能的警告.我制作了一些警卫宏来帮助我让第三方标题从警告中消失,而现在它们对于msvc和clang来说就像魅力一样.我仍然缺少使用Gcc诊断编译指示的正确方法来抑制部分中的每个警告.我举几个例子:

在msvc中我们可以这样做:

#pragma warning(push, 0)
// Code that produces warnings...
#pragma warning(pop)
Run Code Online (Sandbox Code Playgroud)

在clang我们可以做到这一点:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wall"
#pragma clang diagnostic ignored "-Wextra"
// Code that produces warnings...
#pragma clang diagnostic pop
Run Code Online (Sandbox Code Playgroud)

中间的代码现在正在被警告保持沉默.

在Gcc中我们也有类似的pragma指令与clang,我想我可以尝试这样的事情:

#pragma GCC diagnostic push
#pramga GCC diagnostic ignored "-Wall"
#pragma GCC diagnostic ignored "-Wextra"
// Code that produces warnings...
#pramga GCC diagnostic pop
Run Code Online (Sandbox Code Playgroud)

但是在GCC中传递-Wall和-Wextra在诊断忽略的pragma中并不像clang那样工作,并且不会禁用所有可能的警告.而不是传递一个特定的警告来禁用工作:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
void foo (int x) // No longer getting "unused …
Run Code Online (Sandbox Code Playgroud)

c++ gcc warnings pragma

15
推荐指数
1
解决办法
4280
查看次数

cmake 抑制外部库上的警告

我在我的项目中使用 GLAD,并使用 cmake 构建所有内容。

由于这是一个外部库而不是我的代码,我想在构建时完全抑制它的警告,因为我得到了很多这些:

warning: ISO C forbids conversion of object pointer to function pointer type [-Wpedantic]
 glad_glCullFace = ( PFNGLCULLFACEPROC ) load ( "glCullFace" );
                   ^
Run Code Online (Sandbox Code Playgroud)

我该怎么做?我可以将它包含在我的源代码中,或者使用 GLAD 的源代码做一个 add_library,不管哪种方式。

谢谢

warnings cmake suppress-warnings

9
推荐指数
1
解决办法
5915
查看次数

在 CMake 中抑制来自外部库的编译器警告

我正在尝试按照下面复制的 CMake 说明将以下项目https://github.com/whoshuu/cpr#cmake构建到我的项目中:

include(FetchContent)
FetchContent_Declare(cpr GIT_REPOSITORY https://github.com/whoshuu/cpr.git GIT_TAG c8d33915dbd88ad6c92b258869b03aba06587ff9) # the commit hash for 1.5.0
FetchContent_MakeAvailable(cpr)
Run Code Online (Sandbox Code Playgroud)

我的项目已经有一些与主目标链接的其他库,因此我包含了这个新库,如下所示:

target_link_libraries(my_target PRIVATE cpr::cpr PUBLIC other_libraries)
Run Code Online (Sandbox Code Playgroud)

问题在于构建cpr库的警告阻止了项目的构建。我想抑制这些警告。我已尝试SYSTEM按照此处的建议添加关键字:如何抑制库标头中的 GCC 警告?所以代码如下所示:

target_link_libraries(my_target PRIVATE SYSTEM cpr::cpr PUBLIC other_libraries)
Run Code Online (Sandbox Code Playgroud)

但这没有帮助。是否有其他方法可以抑制 CMake 中外部库的警告?如果有帮助的话,我正在使用C++-17 g++-11Ninja。

c++ cmake

8
推荐指数
1
解决办法
1442
查看次数

为什么在GCC/C++中使用"pragma GCC诊断推送"弹出警告?

#pragma GCC diagnostic push

it pop: warning: expected [error|warning|ignored] after â#pragma GCC diagnosticâ
Run Code Online (Sandbox Code Playgroud)

为什么?我在Linux中使用GCC.

我有一个问题,如果我不能使用pop/push,如果忽略影响编译的cpp,不影响其他cpp?如果其他一些包括上限,如果影响呢?

c++ pragma

7
推荐指数
1
解决办法
1万
查看次数

系统上的-isystem包含目录导致错误

以下代码是怎么回事?

#include <cmath>

int
main(int argc, char *argv[])
{
}
Run Code Online (Sandbox Code Playgroud)

在最近的带有GCC 6.1.1的Arch Linux安装中编译时,-isystem /usr/include它会生成以下标志:

$ g++ -isystem /usr/include math.cc 
In file included from math.cc:1:0:
/usr/include/c++/6.1.1/cmath:45:23: fatal error: math.h: No such file or directory
 #include_next <math.h>
                       ^
compilation terminated.
Run Code Online (Sandbox Code Playgroud)

这是一个非常简化的示例;原始命令行为:

$ g++ ... -isystem `llvm-config -includedir` ...
Run Code Online (Sandbox Code Playgroud)

使用LLVM的程序的一部分。在Arch Linux上,LLVM软件包安装时带有其标头目录/usr/include,该标头目录为llvm-config。...包括了-Wextra-Wconversion,它们在LLVM标头中引起警告。与-isystem标志相反-I,该标志通过将LLVM目录视为“系统头” 来防止警告。有关更多信息,请参见GNU C预处理程序文档

但是,如果升级到GCC 6.1.1,则上述错误会显示在内部版本中。

gcc

4
推荐指数
1
解决办法
2968
查看次数

不推荐使用动态异常规范

我有一些用于编译(和工作)的代码,现在我收到了很多以下警告.这是在我对Ubuntu-Mate进行了一次升级之后发生的.

警告:在C++ 11中不推荐使用动态异常规范

它发生在像这样简单的行上(在标题中):

    static Value getPriorityValue(const std::string& priorityName)
    throw(std::invalid_argument);
Run Code Online (Sandbox Code Playgroud)

我得到了与此有关的2545警告!反正有没有告诉编译器忽略这个警告?更改代码的最简单方法是什么?

大多数错误都在第三方软件包中,因此我不想对此软件包进行太多修改.

我的编译器中有-std = c ++ 11标志.

c++ c++11

4
推荐指数
1
解决办法
6392
查看次数

使用g ++构建时如何抑制某些文件中的警告?

例如,我正在构建包含多个*.cpp文件的项目,我只需要从这些文件中提取警告.我使用Eclipse项目中使用的Makefile.

我该怎么做?

更新:

似乎诊断编译用于此:

https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html

c++ eclipse makefile g++ compiler-warnings

2
推荐指数
1
解决办法
2007
查看次数