This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: using ar to make a shared lib


Christopher Bottaro <cbottaro@geocenter.com> writes:

> well because i'm redoing my companies build system and in our lib dir,
> there are like 30 subdirs.  so i just made one file called
> "libtargets" that has a bunch of common targets and rules for our
> libs.  so for most of the makefiles in that libs dir, its just a
> matter of setting a few vars and then including the "libtargets".  as
> it is, most of our lib makefiles just compile a bunch of .o files and
> then add them to some .a file somewhere.  i just wanted to see if i
> could get the shared libs to use "libtargets" also instead of having
> to write a makefile by hand.

You may be able to generate an .a file with all the objects you want
and then use a command like

gcc -shared -o libfoo.so -Wl,-soname,libfoo.so.1 -Wl,--whole-archive libfoo.a

to convert the archive into a proper shared library.  --whole-archive
is a GNU ld feature, if you are using some other linker it may have a
different command line option with the same effect, or you can do

mkdir libfoo.tmp
(cd libfoo.tmp && ar x ../libfoo.a)
gcc -shared -o libfoo.so -Wl,-soname,libfoo.so.1 libfoo.tmp/*.o
rm -rf libfoo.tmp

but this requires twice as much disk space.

zw


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]