LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Posix programming environment setup (https://www.linuxquestions.org/questions/programming-9/posix-programming-environment-setup-345527/)

jfitzger68 07-21-2005 06:36 PM

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

perfect_circle 07-21-2005 07:11 PM

when you compile the program, are you using -lpthread in gcc?
Code:

gcc -o example example.c -lpthread

jfitzger68 07-21-2005 07:21 PM

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!

perfect_circle 07-21-2005 07:38 PM

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 :)

jfitzger68 07-22-2005 10:48 AM

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!

jfitzger68 07-22-2005 01:12 PM

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!


All times are GMT -5. The time now is 06:15 AM.