Search code examples
cgcccompilationcompiler-warningsgcc-warning

How can I disable GNU C compiler/GCC warnings without touching source code?


There're tons of redundant explanations about how to disable GCC warnings being treated as errors as developer of the source code. Now, I'd like to know if there's a way to disable them without touching the source code (including build tool configuration files), i.e., let the compilation continue ignoring the warning. In my understand of the GCC documentation at Options to Request or Suppress Warnings, CXXFLAGS="-w" should be sufficient if specified for ./configure and make, e.g., CXXFLAGS="-w" ./configure && make.

Remark: I know that it is not a good idea to compile a program against the intentions of the developers and communicating an issue and fixing it together is always the better option if not the only.

Background (please read the whole question, especially the remark above and below, I'm not looking for a fix for the following issue!): I'm trying to compile QEMU Git tag v2.1.0 in a Debian 7.6 chroot on Synology DSM 5.0 with armv7 architecture and getting

  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

I played around with some options, and now I just want to know whether it's possible or not in order to achieve better inside in the GNU build tools. I'm very certain that the build result will be at least unreliable if not unusable.

BTW: If you found this through a search engine and are having same or similar trouble with QEMU, see Build of v2.1.0 fails on armv7l due to undeclared __NR_select.


Solution

  • You're right about the -w option, and the easiest way to make sure it propagates everywhere is to put it in the CC variable: CC="gcc -w" ./configure ...

    However, if they turned on this warning as an error specifically, then I don't think you should try to disable it. In that case, the code was obviously intended for this warning not to be possible, and it's likely that something is horribly wrong in your toolchain (e.g. integer types are defined wrong, so that a type they expect to be the same size as pointers is not). You should try to track this issue down or you're just going to be wasting your time with a broken build that crashes when you run it. Why not look at some of the source lines the warning messages reference and see what's actually going on?