COBOL calling a C function within a library using the INITCALL directive.



On Linux/Unix, a COBOL program can call a C function within a library using INITCALL, but on Windows, it gives error: 173 Called program file not found in drive/directory.


INITCALL loads the dll/so, but it needs to know what entry is being called within it.  One way to achieve this is by having the same entry name as the binary module itself.  However, there might be several entries in the dll/so that would need to be called separately. In this scenario, INITCALL behaves differently in Linux/Unix compared to Windows.

When the entry and the shared object name are different, on Linux/Unix, the entry can be called by using the "-e name" flag at compilation time.

On Windows, if the Cobol program cannot find an entry with the same name as the dll/so, the first entry in ordinal position is called. To change this behaviour, any entry within the dll that is to be called by COBOL must be exported. For this, a .def file must be created for the dll containing the relevant entry points. Example:





Then, the .def file must be compiled together with the C source when creating the dll:

cl /LD program.c entryfile.def

Note that the Cobol program and the dll must be in the same directory or on %PATH%.

Comment List