Solved

pthread

Posted on 1999-01-23
2
605 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
wordappend challenge 8 223
wordmultiple challenge 12 156
"Black Box" Testing of Control System Software 2 93
Adjust the codes 3 27
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: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.

749 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