编译错误"SIG_BLOCK undeclared"是什么意思?
What does the compilation error "SIG_BLOCK undeclared" mean?
我在使用 -ansi
编译时收到此代码的错误消息 error: ‘SIG_BLOCK’ undeclared
。
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>
您需要告诉编译器您想要定义 SIG_BLOCK
。
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
sigprocmask(): _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE
所以你可能想通过选项
-D_POSIX_SOURCE
或
-D_POSIX_C_SOURCE=1
例如 gcc
或者,您可以将这些 "requests" 作为预处理器指令放在源代码的顶部:
#define _POSIX_SOURCE
... /* other includes */
#include <signal.h>
或
#define _POSIX_C_SOURCE 1
... /* other includes */
#include <signal.h>
我在使用 -ansi
编译时收到此代码的错误消息 error: ‘SIG_BLOCK’ undeclared
。
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>
您需要告诉编译器您想要定义 SIG_BLOCK
。
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
sigprocmask(): _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE
所以你可能想通过选项
-D_POSIX_SOURCE
或
-D_POSIX_C_SOURCE=1
例如 gcc
或者,您可以将这些 "requests" 作为预处理器指令放在源代码的顶部:
#define _POSIX_SOURCE
... /* other includes */
#include <signal.h>
或
#define _POSIX_C_SOURCE 1
... /* other includes */
#include <signal.h>