[ Usenet FAQs | Search | Web FAQs | Documents | RFC Index ]
To make your own shared object or library of shared objects, you should
know that a shared object cannot have undefined symbols. Thus, if your
code uses any externals from /lib/libc.a, the latter MUST be linked with
your code to make a shared object. Mike Heath (mike@pencom.com) said it
is possible to split code into more than one shared object when externals
in one object refer to another one. You must be very good at
import/export files. Perhaps he or someone can provide an example.
Assume you have one file, sub1.c, containing a routine with no external
references, and another one, sub2.c, calling stuff in /lib/libc.a. You
will also need two export files, sub1.exp, sub2.exp. Read the example
below together with the examples on the ld man page.
---- sub1.c ----
int addint(int a, int b)
{
return a + b;
}
---- sub2.c ----
#include <stdio.h>
void printint(int a)
{
printf("The integer is: %d\n", a);
}
---- sub1.exp ----
#!
addint
---- sub2.exp ----
#!
printint
---- usesub.c ----
main()
{
printint( addint(5,8) );
}
The following commands will build your libshr.a, and compile/link the
program usesub to use it.
$ cc -c sub1.c
$ cc -bM:SRE -bnoentry -bE:sub1.exp -o sub1shr.o sub1.o
$ cc -c sub2.c
$ cc -bM:SRE -bnoentry -bE:sub2.exp -o sub2shr.o sub2.o
$ ar r libshr.a sub1shr.o sub2shr.o
$ cc -o usesub usesub.c -L: libshr.a
$ usesub
The integer is: 13
$
A similar example can be found in the AIX manual online on the web at:
<http://www.rs6000.ibm.com/doc_link/en_US/a_doc_lib/aixprggd/genprogc/create_shared_lib.htm>
Send corrections/additions to the FAQ Maintainer:
Last Update May 13 2007 @ 00:21 AM