我如何在不影响源代码的情况下禁用GNU C编译器/GCC警告?

odopli94  于 2022-11-12  发布在  其他
关注(0)|答案(1)|浏览(215)

作为源代码的开发者,有很多关于如何禁用GCC警告的冗余解释。现在,我想知道是否有一种方法可以在不触及源代码的情况下禁用它们(包括构建工具配置文件),即让编译继续忽略警告.在我对GCC文档的理解中,在 * Options to Request or Suppress Warnings *,如果为./configuremake指定了CXXFLAGS="-w",则CXXFLAGS="-w"就足够了,例如CXXFLAGS="-w" ./configure && make
备注:我知道违背开发者的意图编译程序不是一个好主意,沟通问题并一起修复它总是更好的选择,如果不是唯一的选择。
背景(请阅读整个问题,尤其是上面和下面的备注,我不是在寻找解决以下问题的方法!):我尝试在Synology DSM 5.0上使用armv7架构在Debian 7.6 chroot中编译QEMU Git tag 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上遇到了同样或类似的问题,请参见 * Build of v2.1.0 fails on armv7l due to undeclared __NR_select *。

mcvgt66p

mcvgt66p1#

您对-w选项的看法是正确的,确保它传播到所有地方的最简单方法是将它放在CC变量中:CC="gcc -w" ./configure ...
然而,如果他们打开了 * 这个警告作为一个错误 *,那么我不认为你应该尝试禁用它。在这种情况下,代码显然是为了这个警告是不可能的,很可能是你的工具链中有什么可怕的错误(例如整数类型定义错误,这样他们期望与指针大小相同的类型就不存在了)。您应该尝试跟踪此问题,或者您'我们只是在为一个在运行时崩溃的坏构建浪费时间。为什么不看看警告消息引用的一些源代码行,看看实际上发生了什么呢?

相关问题