From: David E. <de...@us...> - 2006-12-29 07:42:08
|
John R. Culleton wrote: > I am converting a batch of programs from a Microfocus > for Unix system to TinyCobol (Linux) and am having > trouble with subprogram linkages. > Here is the situation: > > In main program "general" I have calls to subprogram > maps03 in the form: > CALL "maps03" USING MAPS03-WS. > ... > The subprogram contains the line: > ... > PROCEDURE DIVISION USING MAPA03-WS. > ... > Let's assume static linkage (simpler?) and Legacy > layout > > 1. What options should I have on the compile of maps03.cbl? > > 2. What options should I have on the compile of general.cbl? It really not difficult, once you understand some basics. First of all COBOL, unlike other languages such as C, does not have a default entry point. Meaning the first program (function) to be executed withing the binary. TC will try to determine which is a main-program, and which are sub-programs. It does so by using the 'STOP RUN', for main, and 'EXIT PROGRAM', for sub-programs. Once TC detects a main-program, it will automatically generate a entry point 'main', and the code to call the COBOL main-program. Since this method does not work 100% of the time, you can override this behaviour using the command line, or resourse file options. Then it will up to the programmer to define the entry point. Note that TC version 0.63, does not allow the use of '-' (dash) in a program name (PROGRAM-ID). This is due to a x86 assembler limitation. Finally, the type of COBOL CALL will determine which type of linkage used. If you use CALL 'literal', then compile time linkage is used. If you use CALL identifier, then run-time linkage is used. Meaning that the TC run-time library will try to find and load the library containing the sub-program. Note that run-time linkage works well on UN*X (ELF), but not so well on Win32 (PE-COFF). > Currently when compiled general.cbl can't find subprogram > maps03 which was compiled with the -a option. > I also compiled it with the -c option. > All are in the same directory. > The assembler pass says: > general.o(.text+0x3dc): In function `general': > : undefined reference to `maps03' Actually that is a linker error. As per you example above, you could use the following: htcobol -c general.cbl htcobol -c maps03.cbl gcc -o what-ever general.o maps03.o -L ... Or if you have a library of routines, you could use the following: htcobol -c sub01.cbl ... htcobol -c subNN.cbl ar cr libsubs.a sub01.o ... subNN.o ranlib libsubs.a gcc -o what-ever general.o -L... -lsubs ... There are some examples in the 'test.code/t07' and 'test.code/t15' directories. Or if you would like some advanced examples see the 'test.code/t33' and 'cobrun/test.code' directories. Hope this helps. |