List Info

Thread: Creating a static lib from objects and another static lib




Creating a static lib from objects and another static lib
country flaguser name
United States
2008-03-18 15:43:19
Folks I am trying to embed a static lib in a new lib that I
am creating with
more objects

my command is 

ar rcs libnew.a a.o b.o oldlib.a

This succeeds but when I link against this new library the
symbols from the
old lib are missing

Any ideas ?
-- 
View this message in context: http://w
ww.nabble.com/Creating-a-static-lib-from-objects-and-another
-static-lib-tp16130317p16130317.html
Sent from the Gnu - Make - Help mailing list archive at
Nabble.com.



_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

Re: Creating a static lib from objects and another static lib
user name
2008-03-18 16:08:04
On Tue, 2008-03-18 at 13:43 -0700, muni2773 wrote:
> Folks I am trying to embed a static lib in a new lib
that I am
> creating with more objects

> ar rcs libnew.a a.o b.o oldlib.a

> This succeeds but when I link against this new library
the symbols
> from the old lib are missing

> Any ideas ?

Note this is not really a problem with GNU make.  You'll
probably have
better support on a list more targeted at compilers or
binutils.

However, on most systems ar cannot take an already-existing
archive as
one of the "objects", and extract all its objects
and install them into
a new archive.  That's simply a supported functionality: you
can't do
it.


In your case the solution is actually pretty simple: just
copy the old
library to the new library, then use ar to add in the new
objects:

	cp oldlib.a libnew.a && ar rs libnew.a a.o b.o

-- 
------------------------------------------------------------
-----------------
 Paul D. Smith <psmithgnu.org>                
http://make.mad-scientis
t.us
 "Please remain calm--I may be mad, but I am a
professional."--Mad Scientist




_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

Re: Creating a static lib from objects and another static lib
country flaguser name
United States
2008-03-18 16:29:17
That helps but I would like to pick your brain if there are
multiple old
libraries ? e.g oldlib1.a and oldlib2.a 

Any ideas ?

Thanks

muni2773 wrote:
> 
> Folks I am trying to embed a static lib in a new lib
that I am creating
> with more objects
> 
> my command is 
> 
> ar rcs libnew.a a.o b.o oldlib.a
> 
> This succeeds but when I link against this new library
the symbols from
> the old lib are missing
> 
> Any ideas ?
> 

-- 
View this message in context: http://w
ww.nabble.com/Creating-a-static-lib-from-objects-and-another
-static-lib-tp16130317p16131043.html
Sent from the Gnu - Make - Help mailing list archive at
Nabble.com.



_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

Re: Creating a static lib from objects and another static lib
user name
2008-03-18 16:41:22
On Tue, 2008-03-18 at 14:29 -0700, muni2773 wrote:
> That helps but I would like to pick your brain if there
are multiple
> old libraries ? e.g oldlib1.a and oldlib2.a

Well, then you're SOL! 

Really, at that point you'll have to do something gross;
about the only
thing you can do is use "ar x" to extract all the
objects in each of the
old libraries, then use "ar r" to add them to the
new library.

You'll probably get the best results by writing a shell
script to do it,
then invoking that from the makefile.  You could have your
own script
named "myar" or whatever that took the command
line you WISH that ar
supported, and implemented it:

	myar rcs libnew.a foo.o oldlib2.a bar.o oldlib1.a biz.o
baz.o

etc.

Of course, if you ask on the binutils mailing list (where
they support
and maintain ar) maybe they'll have a better idea, or maybe
someone will
like the idea so much they'll code up an enhancement to ar
on the spot!

-- 
------------------------------------------------------------
-----------------
 Paul D. Smith <psmithgnu.org>                
http://make.mad-scientis
t.us
 "Please remain calm--I may be mad, but I am a
professional."--Mad Scientist




_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

Re: Creating a static lib from objects and another static lib
country flaguser name
Germany
2008-03-18 16:59:09
> > Folks I am trying to embed a static lib in a new
lib that I am
> > creating with more objects
> >
> > ar rcs libnew.a a.o b.o oldlib.a
> >
> > This succeeds but when I link against this new
library the symbols
> > from the old lib are missing
> >
> > Any ideas ?
>
> Note this is not really a problem with GNU make. 
You'll probably have
> better support on a list more targeted at compilers or
binutils.
>
> However, on most systems ar cannot take an
already-existing archive as
> one of the "objects", and extract all its
objects and install them into
> a new archive.  That's simply a supported
functionality: you can't do
> it.

With GNU ar you can, using an ar-script. On the
command-line, e.g.
  $ ar -M
  AR >create libnew.a
  AR >addmod a.o
  AR >addmod b.o
  AR >addlib oldlib.a
  AR >save
  AR >end
This will create libnew.a with the contents of oldlib.a
merged with a.o and 
b.o.

Of course, you can pipe a make-generated list of these
commands to ar -M
and do this as part of your build process. One of my
Makefiles contains 
something like this:

# $1 = target name, $2 = .o files to include, $3 = .a files
to include
makearchive = "create $(1)n  $(foreach mod,$(2),addmod
$(mod)n)  $(foreach 
lib,$(3),addlib $(lib)n)  savenendn"

prerequisites = a.o b.o libnew.a

libstatic.a: $(prerequisites)
	echo -e $(call makearchive,$,$(filter %.o,$^),$(filter
%.a,$^)) | $(AR) -M


Disadvantages of ar-scripts are:
1. Certain characters are not allowed in filenames given to
"addmod" 
or "addlib", for example '+'.
2. According to the GNU ar manual, this feature's "only
purpose [...] is to 
ease the transition to gnu ar for developers who already
have scripts written 
for the MRI 'librarian' program" (I have no idea what
that "librarian" 
program is, though). This probably does not make it the most
supported 
feature of GNU ar.

> In your case the solution is actually pretty simple:
just copy the old
> library to the new library, then use ar to add in the
new objects:
>
> 	cp oldlib.a libnew.a && ar rs libnew.a a.o
b.o

This is certainly a better approach, for the reasons cited
above.
(It wasn't suitable for me, because one of our application
is build as a 
collection of static libraries, and I needed to break down
some of those 
libraries into smaller libraries again, resulting in the
need to build a 
static library from a couple of other static libraries.)

-- 
 Martin


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )