Piszę program powłoki, który musi obsługiwać sygnały. Moja odpowiedni kod obsługa sygnał związany jest następujący:błędy kompilacji przy użyciu signal.h w systemie Linux
#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);
Kompilacja daje mi następujące ostrzeżenia i błędy:
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'
Czy ktoś może mi powiedzieć, dlaczego ja dostaję te ostrzeżenia i błędy?
usuwanie '-ansi' opuszcza mnie: ' /tmp/ccl4HmT7.o: W funkcji głównej': ' '/home/stu1/s11/gaw9451/Courses/OS_3/os1shell2.c: 68: undefined' 'odniesienie do funkcji handler'a' ' ' collect2: ld zwrócił 1 status wyjścia' Dodanie '-D_POSIX_C_SOURCE' robi to samo. Jakieś pomysły na ten temat? – Ataraxia
Czy masz zdefiniowane 'handler_function'? Zostało to zadeklarowane w twoim pytaniu, ale nie ma na to kodu. Musiałem dodać 'void handler_function (int signal_id) {}', a następnie twój kod skompilowany dobrze. –