Passing options to the linker

You can specify linker options in any of these ways: an invocation command (cob2, cob2_j, or cob2_r), the ld command, or makefile statements.

Any options that you specify in an invocation command that are not recognized by the command are passed to the linker.

Several invocation command options influence the linking of your program. For details about the set of options for a given command, consult documentation for that command. For details about the full set of available linker options, see the related reference about the ld command.

The following table shows the options that you are more likely to need for your COBOL programs. Precede each option with a hyphen (-) as shown.

Table 1. Common linker options
Option Purpose
-bdynamic, -bshared, or -bstatic Controls the processing of -l options and the way that shared objects are processed
-bD:nnnn Instructs the linker to allocate nnnn bytes of heap space for static user data. (The default value is 0.) This space might be needed to run programs that have very large data items defined, particularly data items in the WORKING-STORAGE SECTION.
-bE:zog.exp Exports the symbols that are named in the export file zog.exp
-bhalt:error_level Specifies the maximum error level allowed before the processing of linker commands halts
-bI:zog.imp or -bimport:zog.imp Imports the symbols from the import file zog.imp
-bloadmap:name Requests that a log of linker actions and messages is saved in file name
-bmap:name Writes an address map of the output object file to file name
-bmaxdata:bytes or -bmaxstack:bytes Specifies the maximum amount of space to reserve for the program data segment and stack segment for programs for which the size of these regions is a constraint
-bM:SRE Makes the output module a shared reentrant object
-bnoentry Indicates that this object does not have a main entry point
-bnso Statically links a shared object as an ordinary object file
-brtl or -bnortl Determines which algorithm is used to find libraries that you specify with the -l option
-Ldir Specifies the directory to search for libraries specified by the -l option (default: /usr/lib)
-lname Searches the specified library-file, where name selects the file libname.a (default: libraries listed in cob2.cfg)
-Snnnn Instructs the linker to allocate nnnn bytes of user stack. (The default value is 0.) This space might be needed to run programs that have very large data items defined, particularly data items in the LOCAL-STORAGE SECTION.

Examples: using cob2 for linking