ContentsIndexPreviousNext

M.3.1 Calling Functions in Shared Libraries

ACUCOBOL-GT allows you to use the CALL statement to call subroutines in UNIX shared libraries. Placing native code routines in shared libraries and calling them from your COBOL program is a convenient way to access native code routines without having to link them into the runtime. To use a routine located in a shared library, you must first load, or CALL, that library (see Book 3, Reference Guide, section 6.6 "Procedure Division Statements," CALL Statement, for syntax and rules). For example:

   CALL "sharedlibrary.so"

If no relative or absolute path is specified in the CALL statement, the routine looks for the library in the current working directory and then in the location specified in the LD_LIBRARY_PATH environment variable (see Book 1, User's Guide, section 1.5, "Environment Variables" for more details).

Once the library has been loaded, all of the routines it contains can be called. For example:

   CALL "sharedfunction"

The runtime searches for shared libraries after it has searched for COBOL programs.


Note: While most UNIX systems use a binary format which supports calling subroutines in UNIX shared libraries exactly as described in this section, SCO UNIX (and possibly some other UNIX systems) use different binary formats, namely COFF and ELF. On those systems, in order to support calling shared libraries, the objects and executables must be in the ELF format. See the UNIX "man" page for your C compiler on how to create ELF format objects (on some systems, for example, you specify the "-b elf" C compiler option).