Find the answer to your Linux question:
Results 1 to 5 of 5
Hi- I'm having problems with pthread_spin_init, pthread_spin_lock and pthread_spin_unlock. Here is my sample code: Code: #include <pthread.h> int main&#40;&#41; &#123; pthread_spinlock_t *m1; pthread_spin_init&#40; m1, 0 &#41;; return 0; &#125; I ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2005
    Posts
    2

    pthread_spin_init, pthread_spin_lock, pthread_spin_unlock all undefined when linking


    Hi-

    I'm having problems with pthread_spin_init, pthread_spin_lock and pthread_spin_unlock. Here is my sample code:

    Code:
    #include <pthread.h>
    int main&#40;&#41;
    &#123;
    
            pthread_spinlock_t *m1;
            pthread_spin_init&#40; m1, 0 &#41;;
    
            return 0;
    &#125;
    I get the following linking error:

    /tmp/ccq1GCYN.o(.text+0x25): In function `main':
    : undefined reference to `pthread_spin_init'
    collect2: ld returned 1 exit status

    The man page says I only need to include pthread.h, is there another file I'm missing here?

    I'm using gcc 3.4.2 on Fedora Core 3.

    Thanks!

  2. #2
    Just Joined!
    Join Date
    Oct 2005
    Posts
    2
    Answering my own question... use -lpthread when linking

  3. #3
    Just Joined!
    Join Date
    Feb 2006
    Posts
    6
    Quote Originally Posted by kekoa
    Hi-

    I'm having problems with pthread_spin_init, pthread_spin_lock and pthread_spin_unlock. Here is my sample code:

    Code:
    #include <pthread.h>
    int main()
    {
    
            pthread_spinlock_t *m1;
            pthread_spin_init( m1, 0 );
    
            return 0;
    }
    I get the following linking error:

    /tmp/ccq1GCYN.o(.text+0x25): In function `main':
    : undefined reference to `pthread_spin_init'
    collect2: ld returned 1 exit status

    The man page says I only need to include pthread.h, is there another file I'm missing here?

    I'm using gcc 3.4.2 on Fedora Core 3.

    Thanks!

    did you compile it will -lpthread option?

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Feb 2006
    Posts
    6
    Quote Originally Posted by kekoa
    Hi-

    I'm having problems with pthread_spin_init, pthread_spin_lock and pthread_spin_unlock. Here is my sample code:

    Code:
    #include <pthread.h>
    int main()
    {
    
            pthread_spinlock_t *m1;
            pthread_spin_init( m1, 0 );
    
            return 0;
    }
    I get the following linking error:

    /tmp/ccq1GCYN.o(.text+0x25): In function `main':
    : undefined reference to `pthread_spin_init'
    collect2: ld returned 1 exit status

    The man page says I only need to include pthread.h, is there another file I'm missing here?

    I'm using gcc 3.4.2 on Fedora Core 3.

    Thanks!

    did you compile it with -lpthread option?

  6. #5
    Just Joined!
    Join Date
    Jan 2006
    Location
    India
    Posts
    52
    the '-lpthread' (POSIX Thread library) is used to tell the compiler to see the unresolved symbols in pthread library..

    -- rajesh

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •