以下程序(Linux常用函數alarm),在WindowsXP的Code::Blocks下,使用默認的GNU GCC編譯器,編譯不能通過:
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
void handler() {
printf("hello\n");
}
int main()
{
int i;
signal(SIGALRM,handler);
alarm(5);
for(i=1;i<7;i++) {
printf("sleep %d ...\n",i);
sleep(1);
}
}
總是提示:
F:\C\Linux_C\alarm.c||In function 'main':|
F:\C\Linux_C\alarm.c|12|error: 'SIGALRM' undeclared (first use in this function)|
F:\C\Linux_C\alarm.c|12|error: (Each undeclared identifier is reported only once|
F:\C\Linux_C\alarm.c|12|error: for each function it appears in.)|
||=== 已完成構建: 3 個錯誤, 0 個警告 ===|
是不是沒有正確引用signal.h頭文件啊?