You are not logged in.

#1 2017-11-15 08:55:58

Shamoka
Member
Registered: 2017-02-20
Posts: 16

[solved] signal.h

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

#2 2017-11-15 09:11:46

ayekat
Member
Registered: 2011-01-17
Posts: 1,589

Re: [solved] signal.h

#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)


pkgshackscfgblag

Offline

#3 2017-11-15 09:17:17

Shamoka
Member
Registered: 2017-02-20
Posts: 16

Re: [solved] signal.h

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

#4 2017-11-15 09:22:01

ayekat
Member
Registered: 2011-01-17
Posts: 1,589

Re: [solved] signal.h

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)


pkgshackscfgblag

Offline

#5 2017-11-15 09:25:13

Shamoka
Member
Registered: 2017-02-20
Posts: 16

Re: [solved] signal.h

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

Board footer

Powered by FluxBB