OpenCOBOL Manual
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
OpenCOBOL Manual †
erManual/1
Getting Started
Hello World!
This is a sample program that displays "Hello World":
---- hello.cob -------------------------
* Sample COBOL program
IDENTIFICATION DIVISION.
PROGRAM-ID. hello.
PROCEDURE DIVISION.
DISPLAY "Hello World!".
STOP RUN.
----------------------------------------
The compiler is cobc, which is executed as follows:
$ cobc hello.cob
$ ./hello
Hello World!
The executable file name (i.e., hello in this case) is determined by removing the extension from the source file name.
You can specify the executable file name by specifying the compiler option -o as follows:
$ cobc -o hello-world hello.cob
$ ./hello-world
Hello World!
erManual/2_1
Compile
This chapter describes how to compile COBOL programs using OpenCOBOL Compiler Options
The compiler cobc accepts the options described in this section.
1 Build Target
The following options specify the target type produced by the compiler:
-E
Preprocess only. Compiler directives are executed. Comment lines are removed. COPY statements are expanded. The output goes to the standard-out.
-C
Translation only. COBOL source files are translated into C files. The output is saved in file *.c.
-S
Compile only. Translated C files are compiled by cc. The output is saved in file *.s.
-c
Compile and assemble. This is equivalent to cc -c. The output is saved in file *.o.
-m
Compile, assemble, and build a dynamic-linking module (i.e., a shared library). The
output is saved in file *.so. Without any options above, the compiler tries to build an
executable.
When you build an executable, the compiler implicitly gives the option `-fmain', which includes a main function in the output file.
-fmain
Include the main function in the output.
This option takes effect at the translation stage. If you give this option with -C, you
will see the main function at the end of the generated C file.
2 Source Format
OpenCOBOL supports both fixed and free source format.
The default format is the fixed format. This can be explicitly overwritten by one of the following options:
-free
Free format.
-fixed
Fixed format.
3 Warning Options
-Wall
Enable all warnings
-Wcolumn-overflow
Warn any text after column 72
-Wend-evaluate
Warn lacks of END-EVALUATE
-Wend-if
Warn lacks of END-IF
-Wparentheses
Warn lacks of parentheses around AND within OR
erManual/2_2
Multiple Sources
A program often consists of multiple source files. This section describes how to
compile multiple source files.
This section also describes how to build a shared library that can be used by any
COBOL programs and how to use external libraries from COBOL programs.