Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use libtool to create a static library from a bunch of static libraries

Tags:

c

libtool

I have around 80 static libraries. I would like to create one static library from that.

This answer didn't work for me since I get the following error:

libtool: unrecognized option `-static'

I am also confused as to which mode it needs to be done in. Is it "link" or "install" Since there 20 odd libraries, can I also use "*" to specify all?

I didn't find any information in document expect this which doesn't really answer my question.

FYI..These are the modes:

MODE must be one of the following:

      clean           remove files from the build directory
      compile         compile a source file into a libtool object
      execute         automatically set library path, then run a program
      finish          complete the installation of libtool libraries
      install         install libraries or executables
      link            create a library or an executable
      uninstall       remove libraries from an installed directory
like image 237
Nikhil Avatar asked Jul 25 '14 11:07

Nikhil


1 Answers

I'm probably naively ignoring some consequence, but couldn't you just treat the files directly as archives?

for i in *.a; ar x $i; done
ar r libfoo.a *.o
ranlib libfoo.a

Of course, you'll need some kind of renaming scheme if any of the .o files are the same. Probably something like libname_objectname.o.

like image 94
laindir Avatar answered Oct 05 '22 05:10

laindir