Solved

pthread

Posted on 1999-01-23
2
604 Views
Last Modified: 2013-12-26
Hi:
I write a multi-thread application under Linux (Red Hat 5.1).
I use the pthread_create function. When I compile, it's OK. When I link the program, it said that that the pthread_create is unreferenced. So who will tel me what library should I link woth this program?
Who will offer me a makefile? (Just simple is OK)
Thanks.

0
Comment
Question by:jonalee
2 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1296367
-lpthread
0
 

Accepted Solution

by:
grepya earned 50 total points
ID: 1296368
Some of the  libraries have to be linked in explicitly when you compile your program containing one of the functions from that library. The library names are of the form lib<name>.so
for dynamic library and lib<name>.a for static libraries. So if you want to link against a library ( statically or dynamically)
with the name lib<name>.a or lib<name>.so, you append -l<name>
as the last option of your compiler invokation
( eg. cc threadtest.c -lpthread ) Whether a static or a dynamic link is done depends on how the compiler's defaults have been set up. Nowadays dynamic linking is the default in most cases.

  In your case, you are using functions which reside in the file
/usr/lib/libpthread.so ( in the RedHat distro..) The compiler knows where to look for the library file or if you have your library file in some other location for some reason, you can
give the -L/unusual/path/  as a compiler option. ( you should read the man pages for gcc etc for more details.)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Creating Labels and Frequency list style reports in SAS code 9 105
Expand to include initial dialog with two choices. 9 80
lucky13 challenge 11 154
mapAB Challlenge 35 158
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question