什么是编译错误" SIG_BLOCK未声明"意思?

时间:2015-05-17 04:54:40

标签: c gcc ubuntu-14.04

在使用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>

1 个答案:

答案 0 :(得分:2)

您需要告诉编译器您需要定义SIG_BLOCK

来自man sigaction

  

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>