实际上,您不能禁用GCC链接器警告,因为它存储在您链接的二进制库的特定部分。 (该部分称为.gnu.warning 符号)
但是,您可以将其静音,像这样(这是从的libc-symbols.h提取):
没有它:
#include <sys/stat.h>
int main()
{
lchmod("/path/to/whatever", 0666);
return 0;
}
给出:
$ gcc a.c
/tmp/cc0TGjC8.o: in function « main »:
a.c:(.text+0xf): WARNING: lchmod is not implemented and will always fail
随着禁用:
#include <sys/stat.h>
/* We want the .gnu.warning.SYMBOL section to be unallocated. */
#define __make_section_unallocated(section_string) \
__asm__ (".section " section_string "\n\t.previous");
/* When a reference to SYMBOL is encountered, the linker will emit a
warning message MSG. */
#define silent_warning(symbol) \
__make_section_unallocated (".gnu.warning." #symbol)
silent_warning(lchmod)
int main()
{
lchmod("/path/to/whatever", 0666);
return 0;
}
给出:
$ gcc a.c
/tmp/cc195eKj.o: in function « main »:
a.c:(.text+0xf): WARNING:
有了藏身:
#include <sys/stat.h>
#define __hide_section_warning(section_string) \
__asm__ (".section " section_string "\n.string \"\rHello world! \"\n\t.previous");
/* If you want to hide the linker's output */
#define hide_warning(symbol) \
__hide_section_warning (".gnu.warning." #symbol)
hide_warning(lchmod)
int main()
{
lchmod("/path/to/whatever", 0666);
return 0;
}
给出:
$ gcc a.c
/tmp/cc195eKj.o: in function « main »:
Hello world!
显然,在这种情况下,可以由多个空间或一些广告为您的精彩更换Hello world!
项目。
ld的手册页不会说有任何选项可以关闭链接器警告:( – 2011-06-19 03:41:02