I have written a c code file called "utilfunc.c" this code contains my functions that I will use through my code.
Now when I am compiling my "utilfunc.c" file an error happened telling me that undefined reference to 'main' error message . But on this code I don't want the main . What I want is just implementations for my functions.
Can anybody tell me what is happening here?
here is my code :
include "prodcon.h"
static void signalHandler(int signo)
{
signalflag = 1; // Set the signal flag
}
void initializeWait(void)
{
/* Link handler functions */
if (signal(SIGUSR1, signalHandler) == SIG_ERR)
{
perror("signal");
exit(EXIT_FAILURE);
}
if (signal(SIGUSR2, signalHandler) == SIG_ERR)
{
perror("signal");
exit(EXIT_FAILURE);
}
/* Clear masks */
sigemptyset(&nomask);
sigemptyset(&newmask);
/* Add signals to mask sets */
sigaddset(&newmask, SIGUSR1);
sigaddset(&newmask, SIGUSR2);
/* Block SIGUSR1 and SIGUSR2, and save current signal mask. */
if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
{
perror("sigprocmask");
exit(EXIT_FAILURE);
}
}
void signalParent(pid_t pid)
{
kill(pid, SIGUSR2); // Child tells parent that it is done
}
void waitParent(void)
{
while (signalflag == 0)
{
sigsuspend(&nomask); // Wait for signal from parent
}
signalflag = 0; // Clear the singalflag
/* Restore the signal mask to old value */
if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
{
perror("sigprocmask");
}
}
Add -c to your compiler invocation, so that you only compile the translation unit but do not link it to a complete program:
gcc -c -o foo.o foo.c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With