LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 11-03-2010, 12:13 AM   #1
eteck
Member
 
Registered: Oct 2003
Location: In a Cave on Mars
Posts: 52

Rep: Reputation: 15
static libraries


Hi,

I have a libX.a that I've created (from test.c) and put in /usr/lib/

I've then created another libY.a, that calls functions in libX.a, I've also copied this lib to /usr/lib/

Now when I write a program that uses both these libs, then compile I get:

Code:
bill@micosoftsux:~$ gcc test_prog.c  -Wall -m32 -O -g -lX -lY -o test_prog
/usr/lib/libY.a(test.c.o): In function `test_init':
test.c:(.text+0x111): undefined reference to `test_open'
test.c:(.text+0x237): undefined reference to `test_open'
/usr/lib/libY.a(test.c.o): In function `test_send':
test.c:(.text+0x7e3): undefined reference to `test_write'
test.c:(.text+0x8fc): undefined reference to `test_write'
collect2: ld returned 1 exit status
make: *** [test_prog] Error 1
test.c header files exist in /usr/include/ and I've compiled with -lX -lY, but its not working...

Any ideas?
 
Old 11-03-2010, 12:29 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
I don't mess with static libraries, but from man gcc:
Code:
   Options for Linking
       These options come into play when the compiler links object files into
       an executable output file.  They are meaningless if the compiler is not
       doing a link step.

       ...

       -static
           On systems that support dynamic linking, this prevents linking with
           the shared libraries.  On other systems, this option has no effect.
 
Old 11-03-2010, 12:40 AM   #3
eteck
Member
 
Registered: Oct 2003
Location: In a Cave on Mars
Posts: 52

Original Poster
Rep: Reputation: 15
Well if you don't make static lib's you have not lived. Anyway changed the order of the -l and it worked fine.
 
Old 11-03-2010, 08:39 AM   #4
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Quote:
Originally Posted by eteck View Post
Anyway changed the order of the -l and it worked fine.
Yes, you have to put the libraries with the calling functions in the list before the libraries with the functions that they call.

When the linker loads in a library, it only includes the functions that are required (which is the whole reason for using a library rather than an object file). However, it can only tell that functions are required if they have already been used in previous object files or libraries, since the linking is done in a single pass.

Last edited by neonsignal; 11-03-2010 at 08:40 AM.
 
1 members found this post helpful.
  


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
Static libraries vs shared Libraries catallergy Linux - Newbie 2 03-16-2010 01:30 PM
Making static libraries using qt snjv Linux - Software 0 11-29-2007 07:50 AM
linking static libraries??? birjodh Linux - Newbie 3 06-13-2007 02:54 AM
linking static libraries??? birjodh Linux - General 1 06-07-2007 11:02 PM
Compiling with static libraries trek413 Linux - Newbie 4 10-19-2006 07:14 PM

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

All times are GMT -5. The time now is 06:11 PM.

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