[LCP]creation of a shared library from a static library.

sasidhar p psasidhar at hotmail.com
Mon Nov 19 20:39:24 UTC 2001


Hi,
  I dont want to link two libraries,

$gcc -L . cli.c -lmystuff -ladd

I dont want in the above manner. I want to have a single shared library like 
'mystuff' for my application, which should be able to link the static 
library. Hence my question, can I create a single shared library, 'mystuff' 
in this example, from a combination of static library(libadd) and others 
like b.o

As I have shown a series of commands I followed, there was no problem when I 
gave,

$gcc -shared -Wl,-soname,libmystuff.so.1 \
-o libmystuff.so.1.0.1 libadd.a b.o -lc

Here I tried to create a shared library out of libadd.a(Static library) and 
b.o

There was no problem at this stage, but

$ nm libmystuff.so.* | grep add

is producing no result. That is, shared library is not created properly out 
of the static one...


Thanx,
Sasi.






>From: Andrew Weaver <Andrew.Weaver at tecnomen.fi>
>Reply-To: linuxcprogramming at lists.linux.org.au
>To: "'linuxcprogramming at lists.linux.org.au'" 
><linuxcprogramming at lists.linux.org.au>
>Subject: RE: [LCP]creation of a shared library from a static library.
>Date: Mon, 19 Nov 2001 10:45:36 +0200
>
>Hmmm doesn't seem so does it?
>
>gcc -shared -Wl,-soname,libmystuff.so.1 -o libmystuff.so.1.0.1 a.o b.o -lc
>
>should do it for you as should gcc -L . cli.c -lmystuff -ladd
>
>
> > -----Original Message-----
> > From:	sasidhar p [SMTP:psasidhar at hotmail.com]
> > Sent:	Monday, November 19, 2001 8:33 AM
> > To:	linuxcprogramming at lists.linux.org.au
> > Subject:	[LCP]creation of a shared library from a static library.
> >
> > Hi,
> > Can you create a shared library from a static library?
> > I am facing some problems, can you please spare some time for me?
> >
> > 1. I have 3 files a.c b.c and cli.c
> > 2. i used the following steps
> >
> > $ gcc -fPIC -g -c -Wall a.c
> > $ ar rcs libadd.a a.o
> > $ gcc -fPIC -g -c -Wall b.c
> > $ gcc -shared -Wl,-soname,libmystuff.so.1 -o libmystuff.so.1.0.1 
>libadd.a
> > b.o -lc
> > $ LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH ; export LD_LIBRARY_PATH
> > $ ln -s libmystuff.so.1.0.1 libmystuff.so
> > $ ls
> > a.c a.o b.c b.o cli.c libadd.a libmystuff.so libmystuff.so.1.0.1 myhdr.h
> > $ gcc -L . cli.c -lmystuff
> >
> > This giving me the following error...
> >
> > /tmp/ccbpNOID.o: In function `main':
> > /tmp/ccbpNOID.o(.text+0x1d): undefined reference to `add'
> > collect2: ld returned 1 exit status
> >
> > 'add' is defined in a.c that is the static library...
> >
> > thanx,
> > Sasi.
> >
> >
> > _________________________________________________________________
> > Get your FREE download of MSN Explorer at 
>http://explorer.msn.com/intl.asp
> >
> > _______________________________________________
> > This is the Linux C Programming List
> > :  http://lists.linux.org.au/listinfo/linuxcprogramming List
>_______________________________________________
>This is the Linux C Programming List
>:  http://lists.linux.org.au/listinfo/linuxcprogramming List


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp




More information about the linuxCprogramming mailing list