pthread issue

Discussion in 'C++' started by guddu, Apr 21, 2010.

  1. guddu

    guddu Guest

    Hi,
    I have a pthread issue here.
    I am trying to compile a small pthread code

    #define errexit(code,str) \
    fprintf(stderr,"%s: %s\n",(str),strerror(code)); \
    exit(1);

    /******** this is the thread code */
    void *myfun(void * arg)
    {

    // something something

    }


    /******** this is the main thread's code */
    int main(int argc,char *argv[])
    {
    int worker;
    pthread_t threads[NTHREADS]; // holds thread info
    int ids[NTHREADS]; // holds thread args
    int errcode; //* holds pthread error
    code
    int *status; //* holds return code

    // create the threads
    for (worker=0; worker<NTHREADS; worker++) {
    ids[worker]=worker;
    if (errcode=pthread_create(&threads[worker],// thread
    struct
    NULL, //* default thread
    attributes
    myfun, //* start
    routine
    &ids[worker])) { //* arg to
    routine
    errexit(errcode,"pthread_create");
    }

    }

    /*

    some other code

    */


    return(0);
    }



    I tried compiling this on a Windows commandline with g++ compiler

    C:\C++Files>g++ -lpthread Thread.cpp
    E:\DOCUME~1\VISHAL\LOCALS~1\Temp/ccaZD7xf.o:Thread.cpp:(.text+0xb4):
    undefined reference to `_imp__pthread_create'
    collect2: ld returned 1 exit status

    I am not sure why I am getting this error.

    any suggestions and advice ?
    Guddu
    guddu, Apr 21, 2010
    #1
    1. Advertising

  2. guddu

    guddu Guest

    On Apr 21, 9:43 pm, Paavo Helde <> wrote:
    > guddu <> wrote in news:d503a68e-d223-4004-bb3b-
    > :
    >
    >
    >

    Hi<

    That worked !!

    Thanks a lot for your tip.

    Regards,
    Guddu

    > > C:\C++Files>g++ -lpthread Thread.cpp

    >
    > The libraries must go to the end, otherwise they are ignored. Try:
    >
    > C:\C++Files>g++ Thread.cpp -lpthread
    >
    > hth
    > Paavo
    >
    > > E:\DOCUME~1\VISHAL\LOCALS~1\Temp/ccaZD7xf.o:Thread.cpp:(.text+0xb4):
    > > undefined reference to `_imp__pthread_create'
    > > collect2: ld returned 1 exit status

    >
    >
    guddu, Apr 26, 2010
    #2
    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. R Mar
    Replies:
    0
    Views:
    400
    R Mar
    Jan 3, 2004
  2. Avin
    Replies:
    2
    Views:
    15,589
    Jerald Fijerald
    May 8, 2004
  3. lokb
    Replies:
    7
    Views:
    8,753
    red floyd
    Jul 14, 2004
  4. Keith

    Strange Pthread Behavior On IRIX

    Keith, Jun 25, 2003, in forum: C Programming
    Replies:
    1
    Views:
    810
    Keith
    Jun 26, 2003
  5. guddu

    pthread issue

    guddu, Apr 21, 2010, in forum: C Programming
    Replies:
    5
    Views:
    1,530
    guddu
    Apr 26, 2010
Loading...

Share This Page