Microsoft KB Archive/59563

Overlaid COBOL and C Modules Give LINKer Error L2024

PSS ID Number: Q59563 Article last modified on 03-15-1990

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

Summary: Microsoft C and COBOL programs are allowed to call one another. However, due to routines accessed by the LINKer overlay manager called $$MAIN in LLIBCER.LIB and LCOBOL.LIB, COBOL and C calls cannot be overlaid. If the following programs are compiled and LINKed with overlays, the LINKer displays the following error message: pathspec\LLIBCER.LIB(dos\crt0.asm) : error L2024: $$MAIN : special symbol already defined The following information about interlanguage calling applies to Microsoft COBOL Versions 3.00 and 3.00a for MS-DOS and MS OS/2 and to Microsoft C Version 5.10.

More Information: Microsoft does not test, guarantee, support, or recommend the use of LINK overlays with Microsoft COBOL Versions 3.00 and 3.00a. Customers should not, therefore, rely on LINK overlays with COBOL object modules to help overcome memory-related problems in COBOL. In the following example, the three programs below demonstrate how a Microsoft C program can call a COBOL program. This example executes without errors provided there are no overlays specified. The main program is called CMAIN; the two subs are called CSUB and COBSUB. In this example, a PIC X string is passed from the CMAIN program to the COBSUB program and the CSUB program is used to demonstrate the problem using an overlay module.

Program 1 – CMAIN.C

 * 1) include  int number (int); extern cdecl COBSUB(char *Str); char Str[] = “ABCDEF”; void main(void) { printf (“%d”, number (45)); COBSUB(Str); }

Program 2 – CSUB.C
int number (int n) { return (n); }

Program 3 – COBSUB.CBL
$SET LITLINK IDENTIFICATION DIVISION. PROGRAM-ID. &quot;_COBPROG&quot;. DATA DIVISION. WORKING-STORAGE SECTION. LINKAGE SECTION. 01  Str1          PIC X(6). PROCEDURE DIVISION using Str1. DISPLAY &quot;String from C: &quot; Str1. STOP RUN. To build these programs into a working .EXE program, compile and LINK for MS-DOS as follows: COBOL COBSUB.CBL ; CL /c /Awlf CMAIN.C ; CL /c /Awlf CSUB.C ; LINK /NOE /NOD CMAIN CSUB COBSUB,,,LLIBCE LCOBOL ; To produce the LINKer error as described above, compile in the same manner and use the following LINK command: LINK /NOE /NOD CMAIN (CSUB) COBSUB,,,LLIBCE LCOBOL ; Note: The following error message pathspec.LIB(dos0.asm) : error L2024: $$MAIN : special symbol already defined as described above will be displayed if the C program is the main calling program. If the main calling program is the COBOL program, the following error message pathspec\LCOBOL.LIB(INITRUN) : error L2024: $$MAIN : special symbol already defined is displayed. This behavior is correct since the symbol “$$MAIN” is defined in the first .LIB listed in the LINK command. Additionally, similar errors for protected mode can be created by using the appropriate protected mode compiler and LINKer options.

Copyright Microsoft Corporation 1990.