HP OpenVMS Systems Documentation
You can specify object libraries on the COBOL command line by using certain flags or by providing the file name of the library. These object libraries are also searched by ld for unresolved external references.
When cobol specifies certain libraries to ld , it provides a standard list of COBOL library file names to ld . The ld linker tries to locate each of these library file names in a standard list of library directories. That is, ld attempts to locate each object library file name first in one directory, then in the second, and then in the third directory on its search list of directories.
To display a list of the compilers invoked, files processed, and libraries accessed during linking, specify the -v flag.
In addition to an object file created by the compiler, any linker flags and object files specified on the cobol command are also passed to the ld linker. The linker loads object files according to the order in which they are specified on the command line. Because of this, you must specify object libraries after all source and object files on the cobol command line.
To help identify undefined references to routines or other symbols in an object module, consider using the nm command. For instance, in the following example the nm command filtered by the grep command lists all undefined (U) symbols:
% cobol -c ex.cob % nm -o ex.o | grep U
If the symbol is undefined, U appears in the column before the symbol
name. Any symbols with a U in their names can also be displayed by this
126.96.36.199 Specifying Additional Object Libraries
You can control the libraries as follows:
% cobol simtest.cob -lX
% cobol simtest.cob -L/usr/lib/mytest
When processing a C source file (
suffix) using the
command, you may need to specify the appropriate C libraries using the
188.8.131.52 Specifying Types of Object Libraries
Certain cobol flags influence whether ld searches for an archive ( .a ) or shared object ( .so ) library on the standard list of COBOL libraries and any additional libraries specified using the -l string or -L dir flags. These flags are the following:
% cobol -non_shared mainprog.cob rest.o
External references found in an archive library result in that routine being included in the resulting executable program file at link time.
External references found in a shared object library result in a
special link to that library being included in the resulting executable
program file, instead of the actual routine itself. When you run the
program, this link gets resolved by either using the shared library in
memory (if it already exists) or loading it into memory from disk.
184.108.40.206 Creating Shared Object Libraries
% cobol -O3 -c octagon.cob
The file octagon.o is then used as input to the ld command to create the shared library, named octagon.so :
% ld -shared -no_archive octagon.o \ -lcob -lcurses -lFutil -lots2 -lots -lisam -lsort -lexc -lmld -lm
A description of each ld flag follows: