What is the problem with Pthread_create

Y

yezi

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
 
R

Richard Bos

yezi said:
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
 
D

Dan Henry

yezi said:
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.
 
J

Jordan Abel

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.
 
E

Emmanuel Delahaye

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.
 
E

Emmanuel Delahaye

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top