LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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
  Search this Thread
Old 09-22-2005, 03:03 AM   #1
wmoti
LQ Newbie
 
Registered: Sep 2005
Location: Israel
Posts: 22

Rep: Reputation: 15
Unhappy linking problems


Hi ,
I created a lib.a from several c files.
now I write a test. c case which suppose to call some functions from
the lib.a.
the compilation succedded but the linking not. I get : undefined reference to 'function name' .....
but I have a '.h' file which has the prototypes to these functions and it is included in the test.c file.
please tell me what do I do wrong.
 
Old 09-22-2005, 03:23 AM   #2
addy86
Member
 
Registered: Nov 2004
Location: Germany
Distribution: Debian Testing
Posts: 332

Rep: Reputation: 31
You forgot to tell gcc to link with the library. What commands do you enter to compile and link?
 
Old 09-22-2005, 04:41 AM   #3
wmoti
LQ Newbie
 
Registered: Sep 2005
Location: Israel
Posts: 22

Original Poster
Rep: Reputation: 15
gcc -o test.exe $(OBJ) $(LIBS)
and LIBS = -L. lib1.a lib2.a .......
 
Old 09-22-2005, 05:09 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,433

Rep: Reputation: 203Reputation: 203Reputation: 203
lib.a is not a good name.
a lib must be named:

libname


e.g to link a library called libwmoti

gcc prog.o -lwmoti


the linker implictly looks for a library
named libwmoti
 
Old 09-22-2005, 05:59 AM   #5
wmoti
LQ Newbie
 
Registered: Sep 2005
Location: Israel
Posts: 22

Original Poster
Rep: Reputation: 15
ok I did what you have told me , but nothing ,
still get the error : undefined reference to 'func name'..
 
Old 09-22-2005, 06:35 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,433

Rep: Reputation: 203Reputation: 203Reputation: 203
need more info.
 
Old 09-22-2005, 07:12 AM   #7
wmoti
LQ Newbie
 
Registered: Sep 2005
Location: Israel
Posts: 22

Original Poster
Rep: Reputation: 15
ok ,
I build some libs ( libname1.a.... )with 'ar.....'
after that I wrote a test.cpp file to check these libs.
and the compilation is ok but linking not.
I get some errors of : undefined reference to '.....'
in the makefile of test I have LIBS = -lname ....
and also IFLAGS = -Iincludefiles.h
 
Old 09-22-2005, 07:52 AM   #8
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,433

Rep: Reputation: 203Reputation: 203Reputation: 203
in Makefile


LDFLAGS = -L /lib/directory

LDLIBS = -lname1

post the error message
 
Old 09-22-2005, 08:07 AM   #9
wmoti
LQ Newbie
 
Registered: Sep 2005
Location: Israel
Posts: 22

Original Poster
Rep: Reputation: 15
alraedy done this ,
p.s. the libs , code and exe are in the same folder
just to make it simple.
the develop machine isnot connected to the net , so I'ii try to copy
the msg : In function 'aaa()' file :file_from_libname1.cpp:54 :undefined reference to 'Funcionname from lib'

regards,
Moti
 
Old 09-22-2005, 08:14 AM   #10
wmoti
LQ Newbie
 
Registered: Sep 2005
Location: Israel
Posts: 22

Original Poster
Rep: Reputation: 15
I also checked inside the lib :
nm -g libname.a
and these undefined referened functions are there.
 
Old 09-22-2005, 08:15 AM   #11
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,433

Rep: Reputation: 203Reputation: 203Reputation: 203
post the make output.

Last edited by bigearsbilly; 09-22-2005 at 08:20 AM.
 
Old 09-25-2005, 12:30 AM   #12
wmoti
LQ Newbie
 
Registered: Sep 2005
Location: Israel
Posts: 22

Original Poster
Rep: Reputation: 15
In Function 'JpgFile::JpgStartCompress(int, int ,int )':
JpgFile.cpp:94: undefined reference to 'jpeg_destroy_compress'
.
.
.
and many lines like this one
 
  


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
Linking Problems doubleds Linux - Software 4 12-03-2004 10:49 PM
Linking problems Avatar33 Programming 1 10-05-2004 07:21 PM
Problems linking Tomcat 4.1.30 and Apache 2.0.50 jockster666 Linux - Software 3 09-03-2004 10:03 AM
Problems statically linking with libsdl jakobf Programming 3 08-27-2004 01:20 AM
math.h linking problems spuzzzzzzz Programming 3 02-21-2004 06:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration