G
guddu
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
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