You are not logged in.
Pages: 1
Hi,
I'm trying to use the signal function in a c program but I get a weird error when I try to compile.
Here is the function
#include <signal.h>
int ignore_sigint(void)
{
signal(SIGINT, SIG_IGN);
return 0;
}
However gcc complains that signal SIGINT and SIG_IGN are not defined.
Last edited by Shamoka (2017-11-15 09:25:52)
Offline
#include <signal.h>
int
ignore_sigint(void)
{
signal(SIGINT, SIG_IGN);
return 0;
}
int
main(void)
{
return ignore_sigint();
}
This compiles fine on my machine with
gcc -Wall -Wextra -pedantic -std=c11 blabla.c
Please provide the gcc command you ran and its full output.
--edit
Also, the output of
which gcc
gcc --version
pacman -Qkk gcc glibc
Last edited by ayekat (2017-11-15 09:16:49)
Offline
gcc -Wall -Werror -ggdb -Iincludes -c sources/exec/signal.c -o sources/exec/signal.o
sources/exec/signal.c: In function ‘ignore_sigint’:
sources/exec/signal.c:5:3: error: implicit declaration of function ‘signal’ [-Werror=implicit-function-declaration]
signal(SIGINT, SIG_IGN);
^~~~~~
sources/exec/signal.c:5:10: error: ‘SIGINT’ undeclared (first use in this function)
signal(SIGINT, SIG_IGN);
^~~~~~
sources/exec/signal.c:5:10: note: each undeclared identifier is reported only once for each function it appears in
sources/exec/signal.c:5:18: error: ‘SIG_IGN’ undeclared (first use in this function); did you mean ‘SIGINT’?
signal(SIGINT, SIG_IGN);
^~~~~~~
SIGINT
cc1: all warnings being treated as errors
make: *** [Makefile:30: sources/exec/signal.o] Error 1
[guillaume@Homer ~]$ pacman -Qkk gcc glibc
gcc: 2326 total files, 0 altered files
backup file: glibc: /etc/locale.gen (Modification time mismatch)
backup file: glibc: /etc/locale.gen (Size mismatch)
glibc: 1596 total files, 0 altered files
[guillaume@Homer ~]$ which gcc
/usr/bin/gcc
[guillaume@Homer ~]$ gcc --version
gcc (GCC) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Last edited by Shamoka (2017-11-15 09:23:13)
Offline
Do you happen to have a file called `signal.h` somewhere within your project or include path? (given that the file you're trying to compile is named `signal.c`)
Given how awesome (*cough*) the header include procedure in C is, it might be masking the one in /usr/include/signal.h.
--edit
fixed typo, should've been `signal.c`, not `compile.c`
Last edited by ayekat (2017-11-15 09:25:55)
Offline
Yes I did have a file called signal.h
I renamed it and it compiles now... stupid mistake.
Thank you
Last edited by Shamoka (2017-11-15 09:30:17)
Offline
Pages: 1