[ Usenet FAQs | Web FAQs | Documents | RFC Index ]
Part1 - Part2 - Part3 - Part4 - Part5 - Single Page
Top Document: comp.unix.aix Frequently Asked Questions (Part 4 of 5)
Previous Document: News Headers
Next Document: 2.06: Linking my program fails with strange errors. Why?
-
Search the FAQ Archives
Part1 - Part2 - Part3 - Part4 - Part5 - Single Page
Top Document: comp.unix.aix Frequently Asked Questions (Part 4 of 5)
Previous Document: News Headers
Next Document: 2.06: Linking my program fails with strange errors. Why?
2.05: How do I make my own shared library?
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>
Top Document: comp.unix.aix Frequently Asked Questions (Part 4 of 5)
Previous Document: News Headers
Next Document: 2.06: Linking my program fails with strange errors. Why?
Part1 - Part2 - Part3 - Part4 - Part5 - Single Page
[ Usenet FAQs | Web FAQs | Documents | RFC Index ]
Send corrections/additions to the FAQ Maintainer:
bofh@mail.teleweb.pt (Jose Pina Coelho)
Last Update October 22 2009 @ 05:22 AM