Solved

Can I include libraries in archives.

Posted on 2001-08-03
5
185 Views
Last Modified: 2013-11-18
Hi,
Is it possible to include shared libaries in archives with "ar" command".
For example if i have file1.o and lib1.so, can I make an archive including both of them?

Thanks,
Sasi,
0
Comment
Question by:ksn76
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:bryanh
ID: 6352192
I think the question is, is it possible _not_ to?  I do this with 'ar r file1.o lib1.so'.

If the shared library is stripped (has no symbol table), then you've got a problem.  Then you need something that reconstructs a symbol table from the dynamic symbol section in lib1.so.  I don't know of anything that does that, but it should be feasible.
0
 
LVL 2

Expert Comment

by:dhymes
ID: 6354005
ar, the standard Unix archiver, is routinely used to create Unix object libraries. The resulting file, which ends in ".a", can therefore be referred to as an archive; however, the term library is recommended as it is more descriptive for our purposes. Archive files created by ar can contain any type of file, including text and executable files; in contrast, object libraries contain only compiled object files.

The syntax for building a library from a group of object files is

ar r


for example,

ar r libmultidim.a hypercube.o mobius_strip.o klien_bottle.o tesseract.o

will create a library in the current directory called libmultidim.a, which contains the four object files given in the example.

So, if you are asking "Can I add an .SO file to an object library and expect the linker "ln" to pick up the objects at linktime/runtime the answer is NO.

If you are asking "Can I add an .SO file to an archive file?" The answer is you can add any file to an archive file.
0
 
LVL 2

Accepted Solution

by:
dhymes earned 100 total points
ID: 6354007
ar, the standard Unix archiver, is routinely used to create Unix object libraries. The resulting file,
which ends in ".a", can therefore be referred to as an archive; however, the term library is recommended
as it is more descriptive for our purposes. Archive files created by ar can contain any type of file,
including text and executable files; in contrast, object libraries contain only compiled object files.


The syntax for building a library from a group of object files is

ar r


for example,

ar r libmultidim.a hypercube.o mobius_strip.o klien_bottle.o tesseract.o

will create a library in the current directory called libmultidim.a, which contains the four object
files given in the example.

So, if you are asking "Can I add an .SO file to an object library and expect the linker "ln" to pick
up the objects at linktime/runtime the answer is NO.

If you are asking "Can I add an .SO file to an archive file?" The answer is you can add any file to
an archive file.
0
 
LVL 5

Expert Comment

by:bryanh
ID: 6356152
>So, if you are asking "Can I add an .SO file to an object library and expect the linker "ln" to pick
>up the objects at linktime/runtime the answer is NO.

Well, it works for me.

As .so files are ELF object files, just as .o files are, 'ln' can pick up the objects the same.
0
 
LVL 2

Expert Comment

by:dhymes
ID: 6358334
I pulled the above out of the linux man pages, you may know something they don't, or it is possible that some linkers can handle shared files within an archive file. The linker I am using cannot.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now