Thread: Undefined reference ?

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    30

    Undefined reference ?

    Hello im getting error while compiling my source code:
    Code:
    Undefined reference to "pthread_create"
    Undefined reference to "pthred_join"
    But there is
    Code:
    #include <pthread.h>

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Are you using gcc?
    Quote Originally Posted by gcc manual
    `-pthread'
    Adds support for multithreading with the "pthreads" library. This
    option sets flags for both the preprocessor and linker.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    30
    sorry i forgot about it
    acctualy i was using -lpthread

  4. #4
    Registered User \007's Avatar
    Join Date
    Dec 2010
    Posts
    179
    Are you sure? You shouldn't be getting that if you are on a *nix machine, include the header and link it when you compile on gcc.

  5. #5
    Registered User
    Join Date
    Dec 2010
    Posts
    30
    You mean link this ?
    Code:
     gcc xxx.o xxxx.o -lpthread -o xxxx

  6. #6
    Registered User \007's Avatar
    Join Date
    Dec 2010
    Posts
    179
    gcc /to/my/source.c -o /to/my/output.out -lpthread

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    For gcc, use "-pthread -D_XOPEN_SOURCE=700".

    -pthread tells gcc to include any compiler and linker flags needed by the platform.

    _XOPEN_SOURCE=700 tells all the headers that you're using the latest Posix standard its extensions.
    http://pubs.opengroup.org/onlinepubs...ag_15_02_01_02

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM

Tags for this Thread