Thread: A Simple pthread_join problem

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    284

    A Simple pthread_join problem

    Why the following code fails to ld?
    Code:
    #include <pthread.h>
    
    void *
    routine( void * arg){
        int x = *(int*)(arg);
        printf("%d\n",x);
    }
    
    int main(){
        pthread_t id;
        void * thread_result;
        int status;
    
        int arg1 = 1;
        status = pthread_create(&id, NULL, routine, (void*)(&arg1) );
        status = pthread_join(id, &thread_result);
    
        return 0;
    }
    main.cc:33: undefined reference to `pthread_join'
    collect2: ld returned 1 exit status
    make: *** [main] Error 1

  2. #2
    Registered User
    Join Date
    Apr 2007
    Posts
    284
    I know the answer:

    GLIBC includes some of the pthread functions because it needs them internally. However, it doesn't need all of them, so it doesn't include all of them. I need to pass -lpthread to the compiler to compile pthread using code.
    Last edited by meili100; 09-11-2008 at 12:28 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A simple file I/O problem
    By eecoder in forum C Programming
    Replies: 10
    Last Post: 10-16-2010, 11:00 PM
  2. Problem in simple code.
    By richdb in forum C Programming
    Replies: 6
    Last Post: 03-20-2006, 02:45 AM
  3. Problem in very simple code
    By richdb in forum C Programming
    Replies: 22
    Last Post: 01-14-2006, 09:10 PM
  4. Simple Initialization Problem
    By PsyK in forum C++ Programming
    Replies: 7
    Last Post: 04-30-2004, 07:37 PM
  5. Simple OO Problem
    By bstempi in forum C++ Programming
    Replies: 1
    Last Post: 04-30-2004, 05:33 PM