![]() |
|
|
|
||||||
We taught the compiler how to build and modify object libraries. We did this for two reasons:
If you think of the library as an executable program, then the method of building the library should be intuitive. Just use the -o xxx command line option, substituting the library file name for xxx.
To build a static library named my_library.a containing the objects a.o, b.o and c.o, use these compiler command line options:
KCC -o my_library.a a.o b.o c.o
To build a shared library, use a similar command, but change the extension used in the library file name from .a to the appropriate extension for your system.
Building
archive libraries by repeatedly appending files one at a time using ar r
incurs costs
proportional to the square of the library's size. This technique is
not even recommended for C language archives. But you may also know that the ar r command can replace files
within an existing archive library. This does not apply to C++ archives!
The ar r
operation is not safe for libraries closed by KCC.
Using the "ar r" command on a KCC archive does not
always fail, but there is no simple test to predict failure.
The problems
have to do with correctly instantiating templates formerly assigned
to the file being replaced. There is an elaborate adaptation of the
C++ Prelinker algorithm which can, in theory, support archive modification.
Development, debugging, maintainence and runtime costs of this method are
unfortunately out of proportion to the small feature it enables.
KCC -o libstuff.a a.o j.o
... removes an existing libstuff.a and rebuilds it using just the a.o and j.o files.
At present, there is no way to modify shared or archive libraries.
You have to relink them from .o files saved or recreated in your build directory.
If you wish to create a library that will use the contents of another library, without containing a copy thereof, simply mention the other library in the command line arguments just as you would if you were building an executable. To build a static library this_library.a containing the objects aa.o, bb.o and cc.o, each of which use files from my_library.a, use these compiler command line options:
KCC -o this_library.a aa.o bb.o cc.o my_library.a
To build a shared library, use a similar command, but change the extension used in the library file name from .a to the appropriate extension for your system.
Library Type Platform static shared HP-UX .a .sl All Other Unix .a .so