Search code examples
cobol

libcob: module 'GETSUM' not found - Cobol


I started to learn Cobol a few days ago and I'm wathcing a video about the basics. The problem that I have is that i'm calling a rountine from another file and when I compile the program I get the error libcob: module 'GETSUM' not found. I'm using a virtual machine with wsl2 wIth ubuntu 20.04.4 LTS on windows 10. And as compiler I am using GnuCobol 2.2.0

Code of main file :

       IDENTIFICATION DIVISION.
       PROGRAM-ID. COBOL-TUTORIAL5.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
           01 Num1 PIC 9 VALUE 5.
           01 Num2 PIC 9 VALUE 4.
           01 Sum1 PIC 99.
       PROCEDURE DIVISION.
       CALL 'GETSUM' USING Num1, Num2, Sum1.
       DISPLAY Num1 " + " Num2 " = " Sum1. 
       STOP RUN.
       

Get sum file:

   IDENTIFICATION DIVISION.
   PROGRAM-ID. GETSUM.
   DATA DIVISION.
   LINKAGE SECTION.
       01 LNum1 PIC 9 VALUE 5.
       01 LNum2 PIC 9 VALUE 4.
       01 LSum PIC 99.
   PROCEDURE DIVISION USING LNum1, LNum2, LSum,.
   ADD LNum1 TO LNum2 GIVING LSum.
   EXIT PROGRAM.    

Solution

  • when I compile the program I get the error libcob: module 'GETSUM' not found

    That can't be the case, because this is the COBOL runtime telling you the module is missing, so this only happens when executing, not when compiling.

    You have two general options:

    1. cobc -x COBOL-TUTORIAL5.cob GETSUM.cob
      --> compile everything at once, creating one big binary. In this case you may want to add -static for both faster runtime and for making sure that you indeed include everything necessary (if not you'd get a linker error, commonly a message like "symbol 'GETSUM' not found").

    2. Compile at least GETSUM.cob as module (cobc GETSUM.cob) and have it either in the current directory when COBOL-TUTORIAL5, or use COB_LIBRARY_PATH to point to the place where the modules are located.

    For more details see the GnuCOBOL manual using Multiple source.