gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 20:39:51 25 4
gpt4 key购买 nike

关于如何禁用源代码开发人员将 GCC 警告视为错误的解释有大量冗余。现在,我想知道是否有一种方法可以在不触及源代码(包括构建工具配置文件)的情况下禁用它们,即让编译继续忽略警告。根据我对 GCC 文档的理解, Options to Request or Suppress Warnings ,如果为 ./configuremake 指定,CXXFLAGS="-w" 就足够了,例如 CXXFLAGS ="-w"./configure && make.

备注:我知道违背开发人员的意图来编译程序并不是一个好主意,沟通问题并一起修复它始终是更好的选择,即使不是唯一的选择。

背景(请阅读整个问题,尤其是上面和下面的注释,我不是在寻找以下问题的解决方案!):我正在尝试编译 QEMU使用armv7架构的Synology DSM 5.0上的Debian 7.6 chroot中的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 时遇到相同或类似的问题,请参阅 Build of v2.1.0 fails on armv7l due to undeclared __NR_select

最佳答案

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

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

关于c - 如何在不接触源代码的情况下禁用 GNU C 编译器/GCC 警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25709526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com