在使用error: ‘SIG_BLOCK’ undeclared
进行编译时,我收到此代码的错误消息-ansi
。
sigprocmask(SIG_BLOCK, &my_sig, NULL);
我是否忘了明确某些头文件?这些是我的包含
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/time.h>
答案 0 :(得分:2)
您需要告诉编译器您需要定义SIG_BLOCK
。
glibc的功能测试宏要求(参见feature_test_macros(7)):
sigprocmask(): _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE
所以你可能希望传递选项
-D_POSIX_SOURCE
或
-D_POSIX_C_SOURCE=1
以gcc为例
另外,你可以把那些&#34;请求&#34;作为源代码顶部的预处理程序指令:
#define _POSIX_SOURCE
... /* other includes */
#include <signal.h>
或
#define _POSIX_C_SOURCE 1
... /* other includes */
#include <signal.h>