Christian Westbrook
Christian Westbrook

Reputation: 339

GnuCOBOL entry point not found

I've installed GnuCOBOL 2.2 on my Ubuntu 17.04 system. I've written a basic hello world program to test the compiler.

1       IDENTIFICATION DIVISION.
2       PROGRAM-ID. HELLO-WORLD.
3      *---------------------------
4       DATA DIVISION.
5      *---------------------------
6       PROCEDURE DIVISION.
7           DISPLAY 'Hello, world!'.
8           STOP RUN.

This program is entitled HelloWorld.cbl. When I compile the program with the command

cobc HelloWorld.cbl

HelloWorld.so is produced. When I attempt to run the compiled program using

cobcrun HelloWorld

I receive the following error:

libcob: entry point 'HelloWorld' not found

Can anyone explain to me what an entry point is in GnuCOBOL, and perhaps suggest a way to fix the problem and successfully execute this COBOL program?

Upvotes: 4

Views: 2265

Answers (2)

Ho1
Ho1

Reputation: 1289

According to the official manual of GNUCOBOL, you should compile your code with:

cobc -x HelloWorld.cbl

then run it with

./HelloWorld

You can also read GNUCOBOL wiki page which contains some exmaples for further information.

P.S. As Simon Sobisch said, If you change your file name to HELLO-WORLD.cbl to match the program ID, the same commands that you have used will be ok:

cobc HELLO-WORLD.cbl
cobcrun HELLO-WORLD

Upvotes: 5

Simon Sobisch
Simon Sobisch

Reputation: 7287

Can anyone explain to me what an entry point is in GnuCOBOL, and perhaps suggest a way to fix the problem and successfully execute this COBOL program?

An entry point is a point where you may enter a shared object (this is actually more C then COBOL). GnuCOBOL generates entry points for each PROGRAM-ID, FUNCTION-ID and ENTRY. Therefore your entry point is HELLO-WORLD (which likely gets a conversion as - is no valid identifier in ANSI C - you won't have to think about this when CALLing a program as the conversion will be done internal).

Using cobcrun internally does:

  1. search for a shared object (in your case HelloWord), as this is found (because you've generated it) it will be loaded
  2. search for an entry point in all loaded modules - which isn't found

There are three possible options to get this working:

  • As mentioned in Ho1's answer: use cobc -x, the reason that this works is because you don't generate a shared object at all but a C main which is called directly (= the entry point doesn't apply at all)
  • preload the shared object and calling the program by its PROGRAM-ID (entry point), either manually with COB_PRE_LOAD=HelloWorld cobcrun HELLO-WORLD or through cobcrun (option available since GnuCOBOL 2.x) cobcrun -M HelloWorld HELLO-WORLD
  • change the PROGRAM-ID to match the source name (either rename or change the source, I'd do the second: PROGRAM-ID. HelloWorld.)

Upvotes: 4

Related Questions