What is the problem with Pthread_create

Discussion in 'C Programming' started by yezi, Nov 1, 2005.

  1. yezi

    yezi Guest

    HI:

    I try to use pthread function. However when I compiling the code, the
    message is :
    " undefined reference to `pthread_create'"

    I check the library, the pthread.h is correct . so what is the problem
    with that ?

    Thanks for any idea.

    bin YE
    yezi, Nov 1, 2005
    #1
    1. Advertising

  2. yezi

    Richard Bos Guest

    "yezi" <> wrote:

    > I try to use pthread function. However when I compiling the code, the
    > message is :
    > " undefined reference to `pthread_create'"
    >
    > I check the library, the pthread.h is correct . so what is the problem
    > with that ?


    The problem is twofold. First, that threads, whether pthread.h or other
    kinds, are not ISO C, and therefore off-topic here.
    Second, that you may have included the header which declares that
    function, but have probably not linked in the library which holds the
    actual code. How to link libraries depends on the implementation; a
    common solution is to use the -l option on the compiler command line,
    but which library name needs to follow it I do not know.

    Richard
    Richard Bos, Nov 1, 2005
    #2
    1. Advertising

  3. yezi

    Dan Henry Guest

    yezi wrote:

    > I try to use pthread function. However when I compiling the code, the
    > message is :
    > " undefined reference to `pthread_create'"
    >
    > I check the library, the pthread.h is correct . so what is the problem
    > with that ?


    This newsgroup is not the proper place to ask about this. A Unix or
    Linux group is the proper place.

    That said, pthread.h is not a library, but rather a header file
    declaring an interface to a library. Don't forget to include the
    pthread library in your link.
    Dan Henry, Nov 1, 2005
    #3
  4. yezi

    Jordan Abel Guest

    On 2005-11-01, yezi <> wrote:
    > HI:
    >
    > I try to use pthread function. However when I compiling the code, the
    > message is :
    > " undefined reference to `pthread_create'"
    >
    > I check the library, the pthread.h is correct . so what is the problem
    > with that ?
    >
    > Thanks for any idea.
    >
    > bin YE


    This is off-topic, but there is a similar issue that is less
    off-topic involving the <math.h> functions. For those cases, you'd
    need -lm on many systems; for this particular case you probably need
    something like -lpthread or -pthread. However, this really isn't the
    right place to ask.
    Jordan Abel, Nov 1, 2005
    #4
  5. yezi a écrit :
    > I try to use pthread function. However when I compiling the code, the
    > message is :
    > " undefined reference to `pthread_create'"
    >
    > I check the library, the pthread.h is correct . so what is the problem
    > with that ?


    So what ? A header file (.h) is nothing but an interface. The
    implementation is somewhere else, probably in some library (.lib, .a...).

    The POSIX Trhreads are not part of the standard C library. You
    probably need some extension library. My guess: add -lpthread on the
    linker command line.
    --
    C is a sharp tool
    Emmanuel Delahaye, Nov 1, 2005
    #5
  6. yezi a écrit :
    > I try to use pthread function. However when I compiling the code, the
    > message is :
    > " undefined reference to `pthread_create'"
    >
    > I check the library, the pthread.h is correct . so what is the problem
    > with that ?


    So what ? A header file (.h) is nothing but an interface. The
    implementation is somewhere else, probably in some library (.lib, .a...).

    The POSIX Threads are not part of the standard C library. You
    probably need some extension library. My guess: add -lpthread on the
    linker command line.
    --
    C is a sharp tool
    Emmanuel Delahaye, Nov 1, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vertigo

    pthread_create for class ?

    vertigo, Aug 28, 2004, in forum: Java
    Replies:
    4
    Views:
    969
    Tor Iver Wilhelmsen
    Aug 29, 2004
  2. nightowl
    Replies:
    1
    Views:
    2,169
    Ron Natalie
    Oct 21, 2004
  3. Replies:
    12
    Views:
    1,963
    verec
    Jul 17, 2005
  4. Gary Wessle

    pthread_create error

    Gary Wessle, Oct 21, 2006, in forum: C++
    Replies:
    9
    Views:
    1,027
    Larry Smith
    Oct 21, 2006
  5. Joy
    Replies:
    1
    Views:
    2,870
    Bart van Ingen Schenau
    May 27, 2009
Loading...

Share This Page