I'm having a bit of an issue with this compiling in Linux with gcc. The command I am typing in is gcc -o <program name> <program name>.c. That has been working, even with these library-dependent data types and stuff, until I included sem_init in the middle.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>
/************************************************************************
* method: int main() *
* purpose: to serve as the driving/starting method for the program *
* returns: 0 to the operating system to signal normal completion *
* *
* approach: *
************************************************************************/
int main()
{
/* the semaphores */
sem_t lowercaseSemaphore; /* for the lowercase letters */
sem_t capitalSemaphore; /* for the capital letters */
sem_t digitSemaphore; /* for the digits */
/* initializing all the semaphores basically to 1 */
sem_init(&lowercaseSemaphore, 0, 1);
sem_init(&capitalSemaphore, 0, 1);
sem_init(&digitSemaphore, 0, 1);
/* the three character buffers */
char lowercase; /* for a lowercase letter */
char capital; /* for a capital letter */
char digit; /* for a digit 0-9 */
return 0;
}
The error message ==
Code:
/tmp/ccChuvdk.o: In function `main':
<program name>.c:(.text+0x28): undefined reference to `sem_init'
<program name>.c:(.text+0x43): undefined reference to `sem_init'
<program name>.c:(.text+0x5e): undefined reference to `sem_init'
collect2: ld returned 1 exit status
What's going on here? I've checked the instructor's example, I've checked the man page for sem_init several times, and I've checked my code several times.