Re: Shared Libraries on HP-UX (-shared)
Posted in 1998
Well, Malcom and I decided to actually open some manuals and figure out how things work. We're both on HP/UX 10.x so our results were almost exactly the same and I think we were both surprised how easy it was. To describe my final methods, I'll use a simple example with the following source code: modmain.4gl A 4gl module containing a main function. mod1.4gl A 4gl module containing sub functions. mod2.4gl A 4gl module containing sub functions. modc.c A c module containing sub functions. 1. Put everything except the modmain.4gl in a shared library (for big systems you might want a few). c4gl -c -shared mod1.4gl mod2.4gl modc.c ld -b -o libmine.sl mod1.o mod2.o modc.o The c module could also be compiled with "cc -c +z modc.c". The result is a group of corresponding object files (.o) in PIC form (position independent code, required for use in shared libraries). 2. Compile the main function in non PIC form because it doesn't have to be PIC and it will be slightly smaller compiled normally. c4gl -c modmain.4gl Other modules that for some reason you don't want in a shared library (?) should be included at this point. 3. Create the final program using shared libraries. c4gl -shared -o modmain.4ge modmain.o -L. -l mine Note the "-L." means you don't have to copy or move your shared library elsewhere as the linker will also look for shared libraries in your current directory. 4. Run the program. Because of the way c4gl resolves shared libraries (the "+s" option), your shared libraries don't have to be in any particular place. The environment variable SHLIB_PATH can be used to point to your shared library location at run time. export SHLIB_PATH=/opt/mine modmain.4ge This can be useful if you have a development environment on the same machine. Note: Because PIC objects are considerably larger than normal objects in HP/UX, the size of a large compiled 4gl program will actually be larger when the -shared option is used by itself. This is contrary to the whole purpose of using the -shared option to reduce the code size. Additional savings in code size can be achieved using the strip command or similar options with the linker. Any additional comments are welcome, ---------------------------------------------------------------------- John H. Frantz Power-4gl: Extending Informix-4gl john@rl.is http://www.rl.is/~john/pow4gl.html