The program below uses POSIX pthreads, and the child prints out 5 and the parent prints out 0. On Mac OS X, it compiles and runs correctly. On Linux I get the following error:
/tmp/ccCWW53M.o: In function `main':
q3.c:(.text+0x49): undefined reference to `pthread_create'
q3.c:(.text+0x5a): undefined reference to `pthread_join'
collect2: ld returned 1 exit status
Can anyone tell me what the problem is. I assume that it is a problem with pthread.h, but the problem is the same on Kubuntu, Fedora and Slackware systems that I have tried. pthread.h exists in all cases, and other programs (not using pthreads, but using other system calls) compile and work correctly.
Here is the program:
int value = 0;
void *runner(void *param); /* The Thread*/
int main( int argc, char *argv)
pid = fork();
if (pid == 0) /* Child Process */
pthread_create(&tid, &attr, runner, NULL);
printf("CHILD: Value = %d\n",value); /* Line C*/
else if (pid > 0) /* Parent Process */
printf("PARENT: value = %d\n",value); /* LINE P*/
void *runner(void *param)
value = 5;
Thanks in advance for any help