Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > pthread issue

Reply
Thread Tools

pthread issue

 
 
guddu
Guest
Posts: n/a
 
      04-21-2010
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
 
Reply With Quote
 
 
 
 
guddu
Guest
Posts: n/a
 
      04-26-2010
On Apr 21, 9:43*pm, Paavo Helde <(E-Mail Removed)> wrote:
> guddu <(E-Mail Removed)> wrote in news:d503a68e-d223-4004-bb3b-
> (E-Mail Removed):
>
>
>

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

>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pthread issue guddu C Programming 5 04-26-2010 06:38 AM
Pthread sleep cycle problem lokb C++ 7 07-14-2004 09:04 PM
gcc -pthread option for Linux Avin C++ 2 05-08-2004 09:53 AM
PThread Problem (Urgent Help Needed) R Mar Java 0 01-03-2004 12:33 PM
Strange Pthread Behavior On IRIX Keith C Programming 1 06-26-2003 02:08 PM



Advertisments