在Linux中使用signal.h编译错误 [英] compile errors using signal.h in Linux
本文介绍了在Linux中使用signal.h编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个必须处理信号的shell程序.我相关的信号处理相关代码如下:
I'm writing a shell program that must handle signals. My relevant signal handling related code is as follows:
#include <signal.h>
...
#include <sys/types.h>
...
void installSigactions( int, struct sigaction* );
void handler_function( int signal_id );
...
/*define signal table*/
struct sigaction signal_action;
/*insert handler function*/
signal_action.sa_handler = handler_function;
/*init the flags field*/
signal_action.sa_flags = 0;
/*are no masked interrupts*/
sigemptyset( &signal_action.sa_mask );
/*install the signal_actions*/
sigaction( SIGINT, &signal_action, NULL );
编译给我以下警告和错误:
Compiling gives me the following warnings and errors:
gcc -Wall -ggdb -ansi -static -pedantic -o os1shell2 os1shell2.c
os1shell2.c:35: warning: 'struct sigaction' declared inside parameter list
os1shell2.c:35: warning: its scope is only this definition or declaration,
which is probably not what you want
os1shell2.c: In function 'main':
os1shell2.c:66: error: storage size of 'signal_action' isn't known
os1shell2.c:75: warning: implicit declaration of function 'sigemptyset'
os1shell2.c:78: warning: implicit declaration of function 'sigaction'
谁能告诉我为什么我会收到这些警告和错误?
Can anyone tell me why I'm getting these warnings and errors?
推荐答案
如果从编译行中删除-ansi
,它将起作用.我怀疑问题是当您指定-ansi
时,信号库的posix部分并未包括在内.
It will work if you remove -ansi
from your compile line. I suspect the problem is that the posix parts of the signal library aren't included when you specify -ansi
.
如果您确实不想禁用-ansi,也可以将-D_POSIX_C_SOURCE
添加到编译器选项中.
If you really don't want to disable -ansi, you can also add -D_POSIX_C_SOURCE
to the compiler options.
这篇关于在Linux中使用signal.h编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文