如何在不接触源代码的情况下禁用 GNU C 编译器/GCC 警告


关于

如何禁用GCC警告作为源代码开发人员被视为错误的大量冗余解释。现在,我想知道是否有办法在不接触源代码(包括构建工具配置文件(的情况下禁用它们,即让编译继续忽略警告。根据我对 GCC 文档在请求或抑制警告选项中的理解,如果指定用于./configuremakeCXXFLAGS="-w"应该足够了,例如,CXXFLAGS="-w" ./configure && make

备注:我知道违背开发人员的意图编译程序不是一个好主意,并且传达问题并一起修复它总是更好的选择,如果不是唯一的话。

背景(请阅读整个问题,尤其是上面和下面的评论,我不是在寻找以下问题的修复程序! 我正在尝试在具有 armv7 架构的 Synology DSM 5.0 上的 Debian 7.6 chroot 中编译 QEMU Git 标签 v2.1.0 并获得

  CC    migration-rdma.o
migration-rdma.c: In function 'ram_chunk_start':
migration-rdma.c:521:12: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
migration-rdma.c: In function '__qemu_rdma_add_block':
migration-rdma.c:553:49: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
migration-rdma.c:554:49: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
migration-rdma.c: In function '__qemu_rdma_delete_block':
migration-rdma.c:661:45: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
migration-rdma.c:696:49: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
migration-rdma.c: In function 'qemu_rdma_search_ram_block':
migration-rdma.c:1109:49: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
migration-rdma.c: In function 'qemu_rdma_register_and_get_keys':
migration-rdma.c:1172:50: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
migration-rdma.c:1173:29: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
migration-rdma.c:1173:51: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
migration-rdma.c:1174:29: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
migration-rdma.c: In function 'qemu_rdma_post_send_control':
migration-rdma.c:1558:36: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
migration-rdma.c: In function 'qemu_rdma_post_recv_control':
migration-rdma.c:1614:37: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
migration-rdma.c: In function 'qemu_rdma_write_one':
migration-rdma.c:1862:16: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
migration-rdma.c:1866:53: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
migration-rdma.c:1920:52: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
migration-rdma.c:1921:50: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
migration-rdma.c:1975:49: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
migration-rdma.c:1996:49: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
migration-rdma.c:2008:58: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
migration-rdma.c: In function 'qemu_rdma_registration_handle':
migration-rdma.c:3021:21: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
migration-rdma.c:3086:41: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
cc1: all warnings being treated as errors
make: *** [migration-rdma.o] Error 1

尝试了一些选项,现在我只想知道这是否可能,以便在 GNU 构建工具中实现更好的内部。我非常确定构建结果即使不是无法使用,也至少是不可靠的。

顺便说一句:如果您通过搜索引擎找到此问题,并且在使用 QEMU 时遇到相同或类似的问题,请参阅 v2.1.0 的构建由于未声明__NR_select而在 armv7l 上失败

您对-w选项的看法是正确的,确保它传播到任何地方的最简单方法是将其放在CC变量中:CC="gcc -w" ./configure ...

但是,如果他们专门将此警告作为错误打开,那么我认为您不应该尝试禁用它。在这种情况下,代码显然是为了使此警告不可能实现,并且很可能您的工具链中存在严重错误(例如,整数类型定义错误,因此它们期望的类型与指针大小相同(。您应该尝试跟踪此问题,否则您只会浪费时间在运行时崩溃的损坏版本上。为什么不查看警告消息引用的一些源代码行,看看实际发生了什么?

最新更新