CGO如何抑制警告

I have a cgo application that uses a C library. During the build process, the compiler shows some warnigns:

In file included from ./libsolv-sys/src/qsort_r.c:40:0,
                 from ./libsolv-sys/src/util.c:181,
                 from ./libsolv.go:16:
/usr/include/sys/cdefs.h:1:2: warning: #warning usage of non-standard #include <sys/cdefs.h> is deprecated [-Wcpp]
 #warning usage of non-standard #include <sys/cdefs.h> is deprecated
  ^~~~~~~

This library is not maintained by myself and I am not able to fix this warning directly. I am sick of the warning though.

Question: How do I suppress warnings in CGO?

Used CGO Flags: CFLAGS: -I./libsolv-sys/src -D LIBSOLV_INTERNAL LDFLAGS: ${SRCDIR}/libsolv-sys.a

cgo

1个回答



CGO依靠外部编译器工具链来编译C代码。
例如,在我的Linux机器上,它将默认为GCC进行编译 C代码。</ p>

对于gcc,您要查找的标志是 -w </ code>,因此您的标志应为:</ p>

-I./libsolv-sys/src -D LIBSOLV_INTERNAL -w </ code> </ p>

参考:禁用所有gcc警告 </ p>

如果使用其他工具链,则可能需要另一个标志。</ p>
</ div >

展开原文

原文

CGO relies on an external compiler toolchain to compile your C code. On my Linux machine for example, it will default to GCC to compile C code.

For gcc the flag you are looking for is -w, so your flags would be:

-I./libsolv-sys/src -D LIBSOLV_INTERNAL -w

reference: Disable all gcc warnings

You may need another flag if you are using another toolchain.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐