Find the answer to your Linux question:
Results 1 to 3 of 3
Hello, i'm programming with posix threads and i'm trying to compile the first threaded example in a book and i get this error: /tmp/ccAg2hOE.o: In function `alarm_thread': alarm_thread.c .text+0x1d): undefined ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2005
    Posts
    1

    pthreads


    Hello,
    i'm programming with posix threads and i'm trying to compile the first threaded example in a book and i get this error:

    /tmp/ccAg2hOE.o: In function `alarm_thread':
    alarm_thread.c.text+0x1d): undefined reference to `pthread_detach'
    /tmp/ccAg2hOE.o: In function `main':
    alarm_thread.c.text+0x142): undefined reference to `fprint'
    alarm_thread.c.text+0x1b1): undefined reference to `pthread_create'
    collect2: ld returned 1 exit status

    I've included <pthreads.h> and <stdio.h>. Does anyone know why this is and how to fix it?

    Cheers
    Amit

  2. #2
    Linux Newbie
    Join Date
    Jul 2005
    Location
    Chd,India
    Posts
    135
    i think you are not linking your code with the correct library for pthreads.
    The pthread.h header just contains the function decleration.You also need to link the correct library with your code when compliling.

    I think rt library should do.
    Code:
    gcc -lrt yourcode.c
    The strong shall live and the weak will die
    In the end,only the fittest survive in this world
    - Shishio Makoto

  3. #3
    Just Joined!
    Join Date
    Oct 2005
    Location
    Mass
    Posts
    52
    i think we have -lpthread too right? i forget

  4. $spacer_open
    $spacer_close

Posting Permissions

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