[prog] Posix thread error

Warren Prasad warren_pd at yahoo.com
Thu Nov 25 22:41:35 EST 2004


Hi,
 
I am getting this error while compiling 
a posix thread program.
I m new to posix programming and this is the 
first program i m trying to compile using cc
in Linux AS 2.1.
The error i get is :
---------------------------------------------------------------------------------
/tmp/ccEwkHiy.o: In function `main':
/tmp/ccEwkHiy.o(.text+0x7c): undefined reference to `pthread_create'
/tmp/ccEwkHiy.o(.text+0xb5): undefined reference to `pthread_join'
collect2: ld returned 1 exit status
---------------------------------------------------------------------------------
 
the code is given below.
 
---------------------------------------------------------------------------------
#include <pthread.h>
#define NTHREADS 50000
void *do_nothing(void *null) {
int i;
i=0;
pthread_exit(NULL);
}
main() {
int rc, i, j, detachstate;
pthread_t tid;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
for (j=0; j<NTHREADS; j++) {
  rc = pthread_create(&tid, &attr, do_nothing, NULL);
  if (rc) {
    printf("ERROR; return code from pthread_create() is %d\n", rc);
    exit(-1);
    }
  /* Wait for the thread */
  rc = pthread_join(tid, NULL);
  if (rc) {
    printf("ERROR; return code from pthread_join() is %d\n", rc);
    exit(-1);
    }
  }
pthread_attr_destroy(&attr);
pthread_exit(NULL);
}
---------------------------------------------------------------------------------
 
Please Help!!!!!!!!!!!!!!!!!!!!
 

		
---------------------------------
Do you Yahoo!?
 Take Yahoo! Mail with you! Get it on your mobile phone.


More information about the Programming mailing list