Compiling

Compiler Environment and Options Setup

The compiler uses three levels of controls for compile options.

The first level is the compiler environment. The term “compiler environment” refers to the directories and files htcobol uses to compile a COBOL program. By default, htcobol reads the file htcobolrc from directory /usr/local/share/htcobol to determine the default compile options. The default dynamically loaded libraries are normally in /usr/local/lib. The default location of the preprocessor, htcobolpp, is /usr/local/share/htcobol. These defaults can be overriden by setting environment variables, TCOB_OPTIONS, TCOB_OPTIONS_PATH, TCOB_LD_LIBRARY_PATH, and TCOB_PP_PATH to the file or path you want to use.

The second level of control is the compiler options contained in htcobolrc. The options are documented in the htcobolrc file. Some of the htcobolrc options can be commented out and the compiler will use a default value. The compiler defaults are documented in the htcobolrc file.

BSD users must change the LD_EXTRA_LIBS, and LD_DCALL_LIBS options before using the compiler. The installer will default these two options to refer to the dl dynamic linker, which is not normally used by BSD. BSD users should delete -ldl from the LD_EXTRA_LIBS and LD_DCALL_LIBS options.

The third level of control is the command line options. The command line options override the compile options in htcobolrc. The compile options are documented fully in the htcobol man file.

Unlike many other COBOL compilers, TinyCOBOL does not have in-source-code compiler options.

How to Compile—A Quick Introduction

Experienced Linux and BSD users can skip this section. This section is a simple tutorial to get absolute beginners started.

The TinyCOBOL compiler is named htcobol. The command line options are documented in the htcobol man pages. The general format is:

htcobol [options] [your program name]

The simplest way to get started compiling is through the command line. Shell scripts containing the command line statements can be used. Experienced developers usually use make files.

Command Line Compiling

If you are just getting started, create the following simple program in file and name it hello.cob:

IDENTIFICATION DIVISION.

PROGRAM-ID. HELLO.

PROCEDURE DIVISION.

DISPLAY "Hello, world!"

STOP RUN.

From the command line, cd to the folder containing hello.cob and run the two commands:

htcobol hello.cob

./hello

This should display the message “Hello, world!”

Shell Script Compiling

Place the commands

htcobol hello.cob

./hello

in a file named hello.sh. Run the command

sh hello.sh

This should display the message “Hello, world!”

make File Compiling

A complete tutorial for using make files is outside the scope of this manual. Here is a simple example of using a make file. BSD users will need to substitute gmake for make.

Create a new directory and copy the hello.cob program into it. Create a new file named Makefile and put the following text into it:

# Starter example for hello.cob

SRC_FILE=hello.cob

hello.exe : ${SRC_FILE}

htcobol ${SRC_FILE}

Make sure that you put a tab in front of “htcobol ${SRC_FILE}”, not spaces, otherwise make will not work. Run the commands:

make

./hello

This should display the message “Hello, world!”

Command Line Options

The command line options override the options in the htcobolrc file. Most of the TinyCOBOL command line options are sufficiently documented in the htcobol man page.

-a Create a static runtime library.

-B [static | dynamic] Determines if the libraries are being compiled into the object module or not.

-c Compile into a statically linked module.

-g Generate compiler debugging output.

-l[library name] Link to the library.

-m Create a shared library.

-S [ ]

-t [ ]

-x The default.

-C [ ]

htcobolrc Options

Compile Errors

Troubleshooting

Problem:	Message -- cannot find -lhtcobol

Causes:	The libhtcobol.* library files are not in the linker's search path. The libhtcobol.* library files are normally located in the /usr/local/lib directory. Possible causes are :

*	the libraries are missing,

*	the libraries a located in an unexpected directory,

*	the LD_PATH variable in htcobolrc is not set correctly,

*	htcobolrc is not installed correctly,

*	the -B static htcobol command line option was used and the TinyCOBOL static libraries were not installed.

To fix:	Verify that the LD_PATH variable in htcobolrc points to the correct link directories. LD_PATH is typically set to:

LD_PATH: -L. -L/usr/lib -L/usr/local/lib

Verify that the libhtcobol.* libraries are located where you think they should be. Normally, they are in /usr/local/lib, but your system may have them in a different location. If they are in a different location, verify that LD_PATH is set correctly.

If LD_PATH is set correctly and the libhtcobol.* libraries are where they should be, check the installation of htcobolrc by running the htcobol compiler using the -L option to explicitly decribe where the libraries are located. If the -L option eliminates the error, htcobolrc is not set up correctly.

If the -B static option was used, the static libraries may not have been installed. cd to the TinyCOBOL ./lib directory. Run:

make devel

make install-static

2004-01-28T17:18:09