You can use any of the COBOL invocation commands to both compile and link your programs. The following examples illustrate the use of cob2.
cob2 alpha.cbl beta.cbl
This command creates alpha.o and beta.o, then links alpha.o, beta.o, and the COBOL libraries. If the link step is successful, it produces an executable program named a.out and deletes alpha.o and beta.o.
cob2 zog.cbl -brtl -bshared -lmylib
This command causes the linker to search for the library libmylib.so first, and then the archive library file libmylib.a in each directory in the search path consecutively until either is encountered.
cob2 zog.cbl -bdynamic -llib1 -bstatic -llib2 -brtl
In this case, to satisfy the first library specification, the linker searches for the library liblib1.so first and then the archive library file liblib1.a in each directory (as described in the previous example). However, at the same time the linker searches only for liblib2.a in those same libraries.
cob2 -bnso -bI:/usr/lib/syscalls.exp file1.cbl file2.cbl
cob2 -c file1.cbl # Produce one object file cob2 -c file2.cbl file3.cbl # Or multiple object files cob2 file1.o file2.o file3.o # Link with appropriate libraries
cob2 -o sh_bg beta.cbl gamma.cbl -bM:SRE -bnoentry