Find the answer to your Linux question:
Results 1 to 2 of 2
Hi I am new to GCC.I am trying to execute simple C program to create thread using pthread_create function.when I executes this program , I am getting error as follows: ...
  1. #1
    Just Joined!
    Join Date
    Sep 2007
    Posts
    46

    getting error for pthread_create function in gcc compiler

    Hi

    I am new to GCC.I am trying to execute simple C program to create thread using pthread_create function.when I executes this program , I am getting error as follows:

    [vineeta@vineeta vineeta]$ gcc -o thread thread.c
    /tmp/ccLdGdjo.o(.text+0x2d): In function `main':
    : undefined reference to `pthread_create'
    /tmp/ccLdGdjo.o(.text+0x46): In function `main':
    : undefined reference to `pthread_create'
    /tmp/ccLdGdjo.o(.text+0x59): In function `main':
    : undefined reference to `pthread_join'
    /tmp/ccLdGdjo.o(.text+0x69): In function `main':
    : undefined reference to `pthread_join'
    collect2: ld returned 1 exit statu

    Why I am getting this error and how to resolve this error???

    Thanks
    vineeta

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Hi,

    Welcome to the forum.

    The pthread functions are not included in the standard C library. They are in libpthread, so you should add -lpthread to the command line when you link your program like:

    Code:
    gcc -o thread thread.c -lpthread
    Regards

Posting Permissions

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