Tugger the SLUGger!SLUG Mailing List Archives

RE: [SLUG] compiling to a shared object


That was most helpful. Thanks heaps!

-----Original Message-----
From: Jan Schmidt [mailto:thaytan@xxxxxxxxxxxxxx]
Sent: Thursday, November 29, 2001 7:36 AM
To: 'slug@xxxxxxxxxxx '
Subject: Re: [SLUG] compiling to a shared object


<quote who="Chris Barnes">

> could anyone inform me on how to compile a shared object (.so) file.
> I am trying to use a program i have compiled, but it comes with only 2
modem
> drivers.
> I have found the source for my modem "serial_cb.c", I also found another
> object file "serial_cb.o" but the program I want to run tries to get
drivers
> from .so files.
> I'm a new to this area so if anyone has any ideas that would be most
> appreciated.
> 

.so files are shared library files. You place an object (.o) file into a
shared library with a command like:

gcc -shared input.o -o sharedlib.so

Typically, the object file needs to have been compiled with the -fPIC flag
for the .so file to be any use. -fPIC instructs the compiler to produce
Position Independent Code, which allows it to be relocated within the
program's address space when it is used at run time.

For a command which is portable across more systems, you can learn about
libtool, which knows how to produce shared libraries on many systems and
which automates the production of the correct compiler commands on each
system.

Whether or not the shared library produced will work with the program you
have in mind is another thing: If the serial_cb.c file isn't written to be a
module for the program you are using, then you will almost certainly find
that it won't work. Programs which use shared libraries as loadable-modules
look inside the shared library for specific functions and make calls to
them. If the shared library isn't designed as a module for the program, then
it probably has not got the function calls implemented.

Did I miss anything?

Cheers,
J.
--
Jan Schmidt                                  thaytan@xxxxxxxxxxxxxxxxx

"Stoke me a clipper, I'll be back for Christmas"
  -- Arnold 'Ace' Rimmer, Red Dwarf

Searching for "A Better Way" to a home loan ?. Call RAMS on 13 7267, or go to http://www.rams.com.au

The e-mail and any attachments may contain confidential information.  If you receive it in error you must not use or disclose the information. You must tell us and delete it. We do not waive any legal privilege by sending it. RAMS does not promise that the email is free from virus defect or error.