pthread in ubuntu 10.10

I wrote lines in ubuntu including the function pthread.An error raised:no referrence to the pthread_create;

Then I googled it ,install the glibc-doc but no change in the result.I can't still man the pages about the pthread family function. Someone knows what is the matter?Please help me.Thank you in advance!!
Compile using the -pthreads flag. That may sort it out.

eg.

g++ -o myprog -pthreads myprog.cpp
Last edited on
I tried it. It didn't work.
Can you provide the exact error message please?
ok,“undefined reference to `pthread_create'” and I have included the header in it.
Undefined reference indicates that your linker cannot find the library containing the actual function body. The header will generally contain the function prototype; the library contains the actual code that does the actual work.

You need to link to the threading library. On the command line, probably something like

-pthread

going by the man page ( http://www.kernel.org/doc/man-pages/online/pages/man3/pthread_create.3.html )
You need to link the pthread library, so it's -lpthread.
-pthread(s) implies -lpthread for the linker.
Last edited on
No, just -pthread (or -pthreads, depending on your system).

That will link to pthreads and may cause other side effects as well. Just remember to use -pthread at the compiling AND at the linking stage.
Last edited on
Topic archived. No new replies allowed.