Problem:
A customer had an application written in C and distributed on HP/UX PA-RISC platforms as shared libraries. This application could be invoked from either C or COBOL by linking the libraries to a C or COBOL main program. The libraries themselves depended on other libraries, and were originally built with -L and -l specifying the dependant libraries. The 32-bit linker in HP/UX PA-RISC remembers -L locations as absolute paths, so at runtime the dependant libraries could be found even if SHLIB_PATH did not include their location. Here is an example:
Cmain or COBmain calls sub1 which calls sub2:
> cat Cmain.c
int main(int argc, char **argv)
{
sub1();
}
> cat COBmain.cbl
CALL "sub1".
> cat sub1.c
int sub1(){
disp_hello();
return(0);
}
> cat hide/sub2.c
int disp_hello()
{
printf("Hello world\\n");
return(0);
}
> (cd hide; cc -b -o libsub232.sl sub2.c; cd ..)
> cc -b -o libsub132.sl -Lhide -lsub232 sub1.c
> cc -o Cmain32 -L. -lsub132 Cmain.c
> ./Cmain32
Hello world
> cob -x -o COBmain32 -L. -lsub132 COBmain.cbl
> ./COBmain32
Hello world
This shows that the library "libsub232.sl" hidden in the "hide" subdirectory can be found and dynamically loaded at runtime without SHLIB_PATH including ":hide:", successfully with both Cmain and COBmain.
But when the customer tried to compile in 64-bit mode, Cmain worked but COBmain seemed to lose the -L path information for libsub2:
> (cd hide; cc DA2.0W -b -o libsub264.sl sub2.c; cd ..)
> cc DA2.0W -b -o libsub164.sl -Lhide -lsub264 sub1.c
> cc DA2.0W -o Cmain64 -L. -lsub164 Cmain.c
> ./Cmain64
Hello world
> COBMODE=64 cob -x -o COBmain64 -L. -lsub164 COBmain.cbl
> ./COBmain64
/usr/lib/pa20_64/dld.sl: Unable to find library 'libsub164.sl'.
In the case of COBmain it became necessary to specify SHLIB_PATH at runtime:
> SHLIB_PATH=.:hide:$SHLIB_PATH ./COBmain64
Hello world
Resolution:
The reason is that HP/UX changes the behavior of dynamic linking in 64-bit mode. Locations specified with -L will not be remembered if the b linker option is also used to specify paths, and the "cob -x" command does specify the b linker option. Here is a link into HP/UX documentation:
http://devresource.hp.com/drc/STK/docs/refs/64arch.jsp#runtime
The lesson is that, when working with COBOL in 64-bit mode on HP/UX PA-RISC, SHLIB_PATH (and LD_LIBRARY_PATH too) must be specified to include the location of dependant libraries.



