LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 02: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, 02: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, 03: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, 04:09 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
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, 04: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, 05:35 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
need more info.
 
Old 09-22-2005, 06: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, 06:52 AM   #8
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
in Makefile


LDFLAGS = -L /lib/directory

LDLIBS = -lname1

post the error message
 
Old 09-22-2005, 07: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, 07: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, 07:15 AM   #11
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

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

Last edited by bigearsbilly; 09-22-2005 at 07:20 AM.
 
Old 09-24-2005, 11:30 PM   #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



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

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

All times are GMT -5. The time now is 06:00 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
Open Source Consulting | Domain Registration