Calling between COBOL and C/C++ programs
You can call functions written in C/C++ from COBOL programs and can call COBOL programs from C/C++ functions.
About this task
In an interlanguage application, you can combine 64-bit COBOL programs with 64-bit C/C++ functions, or 32-bit COBOL programs with 32-bit C/C++ functions.
Restriction: You cannot mix 32-bit components and 64-bit
components in an application.
Interlanguage communication between COBOL and C++: In
an interlanguage application that mixes COBOL and C++, follow these
guidelines:
- Specify
extern "C"
in function prototypes for COBOL programs that are called from C++, and in C++ functions that are called from COBOL. - In COBOL, use
BY VALUE
parameters to match the normal C++ parameter convention. - In C++, use reference parameters
to match the COBOL
BY REFERENCE
convention. - COBOL programs follow the C and C++ link and calling conventions. C and C++ programs that will be dynamically called by COBOL programs must be created as DSOs (dynamic shared objects) by compiling them using the gcc -fPIC option to emit position-independent code that is suitable for dynamic linking, and linking them with the gcc -shared option to produce a shared object that can then be linked with other objects to form an executable.
The rules and guidelines referenced below provide further information about how to perform these interlanguage calls.
Unqualified references to "C/C++" in the referenced sections are to GNU GCC compiler.