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 03-31-2010, 06:59 AM   #1
gmsa
LQ Newbie
 
Registered: Mar 2010
Posts: 5

Rep: Reputation: 0
How to add a static library to my own static library


To create a static library, or to add additional object files to an existing static library, I can use a command like this:

ar rcs my_library.a file1.o file2.o

But how to add an existing static library to my own static library.

I have created my own static library using the command above and want to link against the library libuuid.a (placed in /usr/lib/).

Can I use ar to add libuuid.a to my_library.a?
 
Old 03-31-2010, 07:01 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by gmsa View Post
To create a static library, or to add additional object files to an existing static library, I can use a command like this:

ar rcs my_library.a file1.o file2.o

But how to add an existing static library to my own static library.

I have created my own static library using the command above and want to link against the library libuuid.a (placed in /usr/lib/).

Can I use ar to add libuuid.a to my_library.a?
Why do you think you need to add one library to the other in the first place ?
 
Old 03-31-2010, 07:41 AM   #3
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by gmsa View Post
Can I use ar to add libuuid.a to my_library.a?
Yes. Use ar to list the elements of libuuid.a. Then, in a loop, extract each element from libuuid.a into a separate file and add that file to the end of my_library.a.
 
Old 03-31-2010, 07:51 AM   #4
gmsa
LQ Newbie
 
Registered: Mar 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Sergei Steshenko View Post
Why do you think you need to add one library to the other in the first place ?
I have a static library (my_library.a) and in one of its header files I have included <uuid/uuid.h> to be able to use functions like 'uuid_generate'.

When I compile it, I get following error:
> undefined reference to `uuid_generate'

That's why I wanted to link libuuid.a to my own static library.
Is there any other way to resolve this problem?
 
Old 03-31-2010, 08:07 AM   #5
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by gmsa View Post
I have a static library (my_library.a) and in one of its header files I have included <uuid/uuid.h> to be able to use functions like 'uuid_generate'.

When I compile it, I get following error:
> undefined reference to `uuid_generate'

That's why I wanted to link libuuid.a to my own static library.
Is there any other way to resolve this problem?
Linux linker (which is implicitly called by 'gcc') allows as many libraries to be linked against as one wishes. Care should be taken of:
  1. linker search paths (see the '-L' switch);
  2. library order.

Linker can also be told to rescan libraries as needed - this increases link time, but eliminates the need of strict library order.

Read

man ld

, but it requires patience.
 
Old 03-31-2010, 08:25 AM   #6
gmsa
LQ Newbie
 
Registered: Mar 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by wje_lq View Post
Yes. Use ar to list the elements of libuuid.a. Then, in a loop, extract each element from libuuid.a into a separate file and add that file to the end of my_library.a.

I have listed the object files of libuuid.a:

> ar t /usr/lib/libuuid.a
clear.o
compare.o
copy.o
gen_uuid.o
isnull.o
pack.o
parse.o
unpack.o
unparse.o
uuid_time.o

How to extract those object files from the library?
 
Old 03-31-2010, 08:33 AM   #7
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by gmsa View Post
I have listed the object files of libuuid.a:

> ar t /usr/lib/libuuid.a
clear.o
compare.o
copy.o
gen_uuid.o
isnull.o
pack.o
parse.o
unpack.o
unparse.o
uuid_time.o

How to extract those object files from the library?
See in

man 1 ar

the 'x' command. But you do not need to extract.
 
  


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
SDL static library, shared library icecubeflower Programming 6 04-09-2009 03:10 PM
creating static library that includes another static library kskkumar Programming 2 10-22-2007 10:51 AM
Making a static library from a given shared library vro Programming 1 07-27-2007 04:07 PM
LINUX - linking archive (static library) with shared (dynamic) library gurkama Programming 5 03-04-2007 11:11 PM
howto compile bin with my library using all-static and shared linked standart library stpg Programming 4 06-29-2004 04:20 AM

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

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