使用-std=c99参数提示sigset_t未定义

使用-std=c99参数提示sigset_t未定义

编译程序时加了-std=c99后,提示sigset_t未定义。

$ gcc -g -std=c99 test.c -o test
test.c: In function ‘main’:
test.c:6: error: ‘sigset_t’ undeclared (first use in this function)
test.c:6: error: (Each undeclared identifier is reported only once
test.c:6: error: for each function it appears in.)
test.c:6: error: expected ‘;’ before ‘newmask’
test.c:7: error: expected ‘;’ before ‘oldmask’
test.c:9: warning: implicit declaration of function ‘sigemptyset’
test.c:9: error: ‘oldmask’ undeclared (first use in this function)
test.c:11: warning: implicit declaration of function ‘sigprocmask’

因为在C标准中sigset_t并不是<signal.h>中的一部分,要在编译时使用-D_GNU_SOURCE选项,它表示代码符合GNU标准。 就可以解决这个问题。

gcc -g -std=c99 -D_GNU_SOURCE test.c -o test

发表回复