Shared libraries

Lucien W. Van Elsen lwvanels at athena.mit.edu
Thu Jun 27 22:06:48 AEST 1991


In article <schaf.677960266 at socrates.ucsf.edu>, schaf at socrates.ucsf.edu
(Chris Schafmeister%Kollman) writes:
|> I am working on a program that uses X11R4 on the RS6000
|> and I want to distribute the program to other RS6000s without
|> having to move the X11R4 libraries with it.  When
|> I tried to link with '-bnoautoimp' the linker had a fit
|> telling me that it could not link standard library routines like
|> 'open', 'close' etc.
|> 
|> Thanks in advance.

Note- this information is from experimentation; I havn't found a definitive
reference on any of this yet (although I would very much appreciate hearing
from anyone who has!)

In order to link a shared library statically, you need to give an explicit
path -L to the library, and provide whatever imports the library needs to
resolve.  For example, to link 'foo.o' with a non-shared version of the C
library, you'd use:

cc -o foo -bnso foo.o -bimport:/lib/syscalls.exp -L/lib -lc

It is also possible to re-link an executable to use static libraries instead
of shared.  You need to again explicitly specify any imports the library
expects to find, as well as an explicit -L path to the library.  For example:

godtree /tmp) cat > foo.c
main()
{
printf("Hello, world.\n");
}

splat /tmp) cc -o foo foo.c
splat /tmp) ls -l foo
-rwxr-xr-x   1 lwvanels usr         3158 May 23 13:30 foo*
splat /tmp) cc -o foo.new -bnso -bimport:/lib/syscalls.exp foo -L/lib
splat /tmp) ls -l foo.new
-rwxr-xr-x   1 lwvanels usr       223147 May 23 13:31 foo.new*
splat /tmp) ./foo
Hello, world.

-- 
Lucien Van Elsen
MIT Athena Systems Development 



More information about the Comp.unix.aix mailing list