Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19k points)

So, I tried to pick up the following demo off of web;

#include <pthread.h>

#include <stdio.h>

#define NUM_THREADS     5

void *PrintHello(void *threadid)

{

   long tid;

   tid = (long)threadid;

   printf("Hello World! It's me, thread #%ld!\n", tid);

   pthread_exit(NULL);

}

int main (int argc, char *argv[])

{

   pthread_t threads[NUM_THREADS];

   int rc;

   long t;

   for(t=0; t<NUM_THREADS; t++){

      printf("In main: creating thread %ld\n", t);

      rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);

      if (rc){

         printf("ERROR; return code from pthread_create() is %d\n", rc);

         exit(-1);

      }

   }

   pthread_exit(NULL);

}

When I try to compile it on Ubuntu 9.04, following error gets thrown at me:

corey@ubuntu:~/demo$ gcc -o term term.c

term.c: In function ‘main’:

term.c:23: warning: incompatible implicit declaration of built-in function ‘exit’

/tmp/cc8BMzwx.o: In function `main':

term.c:(.text+0x82): undefined reference to `pthread_create'

collect2: ld returned 1 exit status

Any idea what im doing wrong?

1 Answer

0 votes
by (33.1k points)

You should simply try this command:

gcc -pthread -o term term.c

Hope this answer helps you!      

Browse Categories

...