I am working on UNIX platform. I have three lib files and one object
file of which I want to make single Library. structure is as below
PWD/libone/libone.a
PWD/libone/libtwo.a
PWD/libmin/libmin.a
PWD/main.o
I want to compile/combine these all into one SINGLE STATIC LIBRARY
with the name libfinal.a
I tried the following
$ar -rc libfinal.a ./libone/libone.a ./libtwo/libtwo.a ./libmin/
libmin.a main.o
and it generated the libfinal.a but when I link it with main function
(main2.c) using
$gcc -o run main2.c -lfinal -L./
I get the undefined reference error for the functions which were
actually part of previous libraries
I tried fixing it with
$ranlib libfinal.a
assuming that may be just index was missing but it didn't help and it
won't because
$nm libfinal.a
gives the error that unknown format of libone.a libtwo.a and libmin.a
Is there any other way on UNIX based platforms to generate SINGLE
STATIC LIBRARY out of other multiple static LIBRARIES and object
files.
http://www.mail-archive.com/cm...@cmake.org/msg07427.html
has created a panic in me.
Thanks for uregent help
vipin
> Is there any other way on UNIX based platforms to generate SINGLE
> STATIC LIBRARY out of other multiple static LIBRARIES and object
> files.
Extract the object files from the existing libraries with `ar x'. Then
create the new library out of all the extracted object files and any new
ones using `ar rcs'. (If your version of `ar' does not know the `s'
option, then skip it and run `ranlib' afterwards.)
Thanks. It worked But I have something extra for you guys.
When I was making libfinal.a from {libone.a libtwo.a libmin.a main.o }
later on I observed that I had to use /usr/lib/libpthread.a also for
linking.
Following the same method, i extracted all the lib*.a (including /usr/
lib/libpthread.a) and then did
$ar x libone.a libtwo.a libmin.a libpthrea.a
$ar rcs libfinal.a *.o
$gcc -o run main2.o -lfinal
but it gave an undefined reference error for
<__pthread_reset_main_thread, _errno, _h_errno > to name a few
ANOTHER ATTEMPT
-------------------
i tried the following
$ar x libone.a libtwo.a libmin.a
$ar rcs libfinal.a *.o
$gcc -o run main2.o -lfinal -lpthread
basically linking -pthread.a later on and the program works now.
Not sure what's wrong happening when I am trying to extract and
earchive libpthread.a.
Looking for your suggestions.???
vipin
Unfortunately ar does not support this. You will have to extract the
object files and then combine then into a static library.
ar -xv libone/libone.a
ar -xv libone/libtwo.a
ar -xv libmin/libmin.a
ar -rc libfinal.a *.o
--
rahul