Begin File: mkshlib-demo.tar.gz Description:This package is an example to illustrate the subtleties of mkshlib Keywords: mkshlib Version: Entered-date: Author: Ported-by: Original-site: Copying-policy: CMU Supplemental: This package a contrived example to illustrate some of the subtleties of mkshlib. The following files should be found here: Makefile - build the example. data.c - exported data from the shared lib. imports.h - macroes for imported data and code items. ex.h - definitions of common data and functions. example.c - main program for building ex1 & ex2. funcA.c - a function which is placed in the shared lib. funcB.c - a function which is placed in the shared lib. myfuncB.c - a version of funcB to be statically linked. tlib.sl - specification for building a shared library. The features demostrated are: - Defining a shared library function for use by client programs. - Exporting data definitions from a shared library. - Importing data (and code) definitions from a client program. - Exporting and importing the same datum or code (ie. default). testname and uname are defined in data.c. These data items are both exported, which means clients of the library can use them directly. Uname is also imported. This means that if a client defines the symbol itself, the shared library will use it. Imported data symbols cost one pointer dereference per use. The symbol funcB() is available as a branch, and also imported. If an application defines its own funcB (as is done in myfuncB.c), the shared library will invoke it rather than the one bound to the library. This costs one pointer dereference per invocation. The makefile builds three programs: ex1, ex2 and tlib. The latter is the target shared library. ex1 redefines the symbols funcB, uname and testname. The expected output of ex1 is: funcA.c: uname =ex1 testname = testname defined in data.c myfuncB.c: uname =ex1 testname = testname, defined in myfuncB.c myfuncB.c: uname =ex1 testname = testname, defined in myfuncB.c example.c: uname = ex1 testname =testname, defined in myfuncB.c Note that all modules are using a consistant uname, but the program (example.c and myfuncB.c) have a different testname than funcA.c does. Also note that when funcA invokes funcB, it is invoking the one the program defined, not the one in the shared library. ex2 uses only the shared library (ie. doesn't redefine any of the symbols) and it's output is: funcA.c: uname =ex2 testname = testname defined in data.c funcB.c: uname =ex2 testname = testname defined in data.c funcB.c: uname =ex2 testname = testname defined in data.c example.c: uname = ex2 testname =testname defined in data.c If you have any problems, I can be reached on quics as "steve", or as "steve@qnx.com" archive contents: drwxrwxr-x 0 steve techies Jun 29 14:18 mkshlib-demo -rw-rw-r-- 0 steve techies 509 Jun 29 14:18 mkshlib-demo/Makefile -rw-rw-r-- 0 steve techies 91 Jun 29 11:51 mkshlib-demo/data.c -rw-rw-r-- 0 steve techies 56 Jun 29 11:57 mkshlib-demo/imports.h -rw-rw-r-- 0 steve techies 127 Jun 29 11:56 mkshlib-demo/ex.h -rw-rw-r-- 0 steve techies 220 Jun 29 12:10 mkshlib-demo/example.c -rw-rw-r-- 0 steve techies 1437 Jun 29 12:02 mkshlib-demo/funcA.o -rw-rw-r-- 0 steve techies 608 Jun 29 12:02 mkshlib-demo/funcB.o -rw-rw-r-- 0 steve techies 346 Jun 29 12:00 mkshlib-demo/funcA.c -rw-rw-r-- 0 steve techies 427 Jun 29 12:02 mkshlib-demo/data.o -rw-rw-r-- 0 steve techies 669 Jun 29 12:02 mkshlib-demo/myfuncB.o -rw-rw-r-- 0 steve techies 153 Jun 29 12:00 mkshlib-demo/funcB.c -rw-rw-r-- 0 steve techies 2547 Jun 29 14:17 mkshlib-demo/README -rw-rw-r-- 0 steve techies 286 Jun 29 12:03 mkshlib-demo/tlib.sl -rw-rw-r-- 0 steve techies 190 Jun 29 12:00 mkshlib-demo/myfuncB.c End