LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 07-21-2005, 06:36 PM   #1
jfitzger68
LQ Newbie
 
Registered: Jul 2005
Location: San Rafael, CA, USA
Distribution: Cygwin, FedoraCore 4
Posts: 18

Rep: Reputation: 0
Question Posix programming environment setup


I have just installed FedoraCore 4 using the default Workstation paackage profile and I cannot link programs that reference Posix calls like pthread_create(). I cannot find documentation on what my environment variables should be (I have /usr/include and /usr/lib). When I query 'getconf GNU_LIBPTHREAD_VERSION' I get: NPTL 2.3.5. Everything seems to be okay; I can even find pthread.h in /usr/include. What's missing?

Thanks,
Josh
SF, CA
 
Old 07-21-2005, 07:11 PM   #2
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 52
when you compile the program, are you using -lpthread in gcc?
Code:
gcc -o example example.c -lpthread
 
Old 07-21-2005, 07:21 PM   #3
jfitzger68
LQ Newbie
 
Registered: Jul 2005
Location: San Rafael, CA, USA
Distribution: Cygwin, FedoraCore 4
Posts: 18

Original Poster
Rep: Reputation: 0
No, I wasn't. That worked! Thanks.

Funny, I am learning this stuff from the book "GNU/Linux Application Programming' and he does mention that you need that switch!
 
Old 07-21-2005, 07:38 PM   #4
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 52
A header file *.h in most cases only contains a definition of a function.
The body of a function is inside a precompiled library. So unless the function is inside the standard library, you need to specify the library your executable should be linked against. Otherwise you'll get undefined reference errors. All the pthread functions are in libpthread.so
so you need to specify -lpthread (you always omit the lib) when compiling something.
It should be documented in the guide you are using ( or maybe they thought it's obvious...)

P.S. Ahhhh and welcome to LQ
 
Old 07-22-2005, 10:48 AM   #5
jfitzger68
LQ Newbie
 
Registered: Jul 2005
Location: San Rafael, CA, USA
Distribution: Cygwin, FedoraCore 4
Posts: 18

Original Poster
Rep: Reputation: 0
Talking

I just assumed without any real justification that all Posix services were now in the default libraries and it didn't even occur to me that they might be in their own that required an explicit compiler switch. But yes, it would have been helpful for the author of the book to include that wee detail.
Anyhoo, that you very much for the help!
 
Old 07-22-2005, 01:12 PM   #6
jfitzger68
LQ Newbie
 
Registered: Jul 2005
Location: San Rafael, CA, USA
Distribution: Cygwin, FedoraCore 4
Posts: 18

Original Poster
Rep: Reputation: 0
Angry

By the way, I have just spent the last two hours trying to figure out which library I need to link to to use the posix queue calls. I cannot believe this information is this difficult to discover, but no Google search I can think of gives me more than a mention of the mqueue.h header file. Do you know of a resource that discusses libraries?

Arrrrgh!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
POSIX Thread programming problem... rajsun Programming 0 10-07-2005 11:18 PM
c programming compliant with posix ---HELP! v333k Programming 4 02-28-2005 03:08 PM
POSIX and Graphics programming in C varunnarang Programming 3 01-05-2005 09:27 AM
POSIX thread Programming msriram_linux Programming 4 11-21-2004 03:14 PM
Would like to setup programming environment in linux? northfield Linux - Newbie 7 08-16-2002 09:32 AM


All times are GMT -5. The time now is 12:19 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration