compiling a simple program

D

Daud

Hi there ...

I need to know how to compile the program idba1EnableSignal.c to get
idba1EnableSignal.o.
I tried like below but I got some errors. I believe it is because it
cannot find signal.h but I just don't know how to include this when
compiling. I am not a c-programmer.

$ gcc -c idba1EnableSignal.c -ansi
idba1EnableSignal.c: In function `idba1EnableSignal':
idba1EnableSignal.c:25: error: `SIGHUP' undeclared (first use in this
function)
idba1EnableSignal.c:25: error: (Each undeclared identifier is reported
only once
idba1EnableSignal.c:25: error: for each function it appears in.)
idba1EnableSignal.c:26: error: `SIGQUIT' undeclared (first use in this
function)
idba1EnableSignal.c:27: error: `SIGKILL' undeclared (first use in this
function)

idba1EnableSignal.c
------------------------
#include <sys/signal.h>

extern void CleanUp();

void idba1EnableSignal()
{
signal(SIGINT, CleanUp);
signal(SIGHUP, CleanUp);
signal(SIGQUIT, CleanUp);
signal(SIGKILL, CleanUp);

return;
}

Thanks.
Daud
 
K

khurana77

sys/signal.h file is in /usr/include/sys/include

By defaukt compiler looks into /usr/include.

Try giving the path of sys/signal.h using -I option in gcc
 
R

Roger Leigh

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

khurana77 said:
sys/signal.h file is in /usr/include/sys/include

By defaukt compiler looks into /usr/include.

Try giving the path of sys/signal.h using -I option in gcc

This is offtopic, but also incorrect. The correct include is
<signal.h> (see SUSv3).


- --
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iD8DBQFCnFEEVcFcaSW/uEgRAsAqAKCQOJtK+ftnBofU91u/jKbvdbTGxwCg5I6G
2YV/KZOBKipoiumKo+2pnT4=
=5XiC
-----END PGP SIGNATURE-----
 
C

CBFalconer

Daud said:
.... snip ...
#include <sys/signal.h>

No such thing in standard C - use said:
extern void CleanUp();

void idba1EnableSignal()
{
signal(SIGINT, CleanUp);
signal(SIGHUP, CleanUp);
signal(SIGQUIT, CleanUp);
signal(SIGKILL, CleanUp);

return;
}

Only said:
From N869.

[#3] The macros defined are

SIG_DFL
SIG_ERR
SIG_IGN

which expand to constant expressions with distinct values
that have type compatible with the second argument to, and
the return value of, the signal function, and whose values
compare unequal to the address of any declarable function;
and the following, which expand to positive integer constant
expressions with type int and distinct values that are the
signal numbers, each corresponding to the specified
condition:

SIGABRT abnormal termination, such as is initiated
by the abort function

SIGFPE an erroneous arithmetic operation, such as
zero divide or an operation resulting in
overflow

SIGILL detection of an invalid function image, such
as an invalid instruction

SIGINT receipt of an interactive attention signal

SIGSEGV an invalid access to storage

SIGTERM a termination request sent to the program

[#4] An implementation need not generate any of these
signals, except as a result of explicit calls to the raise
function. Additional signals and pointers to undeclarable
functions, with macro definitions beginning, respectively,
with the letters SIG and an uppercase letter or with SIG_
and an uppercase letter,197) may also be specified by the
implementation. The complete set of signals, their
semantics, and their default handling is implementation-
defined; all signal numbers shall be positive.
 
K

khurana77

Its One and the same thing in Linux sys/signal.h includes the file
signal.h as
#include <signal.h>
 
M

Mark

khurana77 said:
Its One and the same thing in Linux sys/signal.h includes the file
signal.h as
#include <signal.h>

On FreeBSD signal.h includes sys/signal.h (not vice versa)
I'd take another look at your headers - according to the standard
the macros are supposed to be defined after the inclusion of signal.h
(note - the standard doesn't refer to sys/signal.h anywhere!)
That being said, the correct include is <signal.h> and NOT sys/signal.h
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top