LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 03-26-2005, 03:09 AM   #1
tekin
LQ Newbie
 
Registered: Mar 2005
Distribution: Slackware 10.1
Posts: 5

Rep: Reputation: 0
Compiling&Linking Error


Hello everyone,

I wrote a program that uses posix threads.i include header files to my project
and i compile with

gcc -c piThreads.c

that's ok i have a piThreads.o file but when i want to link this file with

gcc -o piThreads.o piThreads.c

i have an error like this :

/tmp/ccgNQ6AM.o(.text+0x14d): In function `main':
: undefined reference to `pthread_create'
/tmp/ccgNQ6AM.o(.text+0x15d): In function `main':
: undefined reference to `pthread_join'
collect2: ld returned 1 exit status

i included pthread.h file.

i tried to compile and link my project in redhat, it succesfully compile and link
also i have no problem at execution time...

when i look at pkgtool for libraries, i can see these libs for gcc

glib-1.2.10.i386-2
glib2-2.6.2-i486-1
glib2-2.3.4-i486-1

also i cannot add math.h library to my project too...

i really need help for this.

Thanx to all..
 
Old 03-26-2005, 04:27 AM   #2
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,447

Rep: Reputation: 95
Did you try :
gcc -o piThreads.o piThreads.c -lpthread

And if you want math.h library:
gcc -o piThreads.o piThreads.c -lpthread -lm
 
Old 03-26-2005, 06:48 AM   #3
tekin
LQ Newbie
 
Registered: Mar 2005
Distribution: Slackware 10.1
Posts: 5

Original Poster
Rep: Reputation: 0
yep, that's worked.

is there other parameters like (-lpthread, -lm ..) and how can i learn them?
and why am i need to add these?
i mean, isnt it enough to add .h ?


Thank you keefaz..
 
Old 03-26-2005, 08:21 AM   #4
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,447

Rep: Reputation: 95
You need to add these to tell to the linker what shared library to link, eg

-lm : link math library to access math function
when you tell #include math.h, you just include the math functions definition, not the
math function code

You learn them by experience, there is not specific method to learn, just work
but for pthread, the lib is /usr/lib/libpthread.so and to link it you remove the 'lib' prefix
so -lpthread
 
Old 03-26-2005, 08:36 AM   #5
tekin
LQ Newbie
 
Registered: Mar 2005
Distribution: Slackware 10.1
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Transcode & FFMPEG compiling error CrEsPo Slackware 2 05-10-2005 03:17 PM
compiling and linking C programs node047 Linux - General 2 04-20-2005 11:47 AM
compiling linking help blackzone Programming 1 02-13-2005 10:40 PM
Compiling GLIBC, and linking it correctly Boudewijn Linux - Newbie 5 11-08-2004 11:11 AM
compiling and linking boku Programming 5 12-25-2002 09:23 AM


All times are GMT -5. The time now is 09:08 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