Preparing OO applications

Use the cob2_j command to link OO COBOL applications. When you link using cob2_j, thread-enabled libraries are used for linking the application.

To prepare an OO COBOL client program for execution, link the object file to create a shared library.

To prepare a COBOL class definition for execution:

  1. Link the object file to create a shared library.

    You must name the resulting shared library libClassname.so, where Classname is the external class-name. If the class is part of a package and thus there are periods in the external class-name, you must change the periods to underscores in the shared library name. For example, if class Account is part of the com.acme package, the external class-name (as defined in the REPOSITORY paragraph entry for the class) must be com.acme.Account, and the shared library for the class must be libcom_acme_Account.so.

  2. Compile the generated Java source with the Java compiler to create a class file (.class).

For a COBOL source file Classname.cbl that contains the class definition for Classname, you would use the following commands to compile and link the components of the application:

Table 1. Commands for compiling and linking a class definition
Command Input Output
cob2_j -c Classname.cbl Classname.cbl Classname.o, Classname.java
cob2_j -o libClassname.so -bnoentry -bM:SRE Classname.o Classname.o libClassname.so
javac Classname.java Classname.java Classname.class

After you issue the cob2_j and javac commands successfully, you have the executable components for the program: the shared library libClassname.so and the class file Classname.class. All files from these commands are generated in the current working directory.

Example: compiling and linking a COBOL class definition