developer's diary

最近はc#のエントリが多いです

UbuntuのOpenCOBOLでソースをコンパイルして実行


インストールはUbuntuにOpenCOBOLをインストールする - developer's diaryにも書いたけどもapt-getでできました。

sudo apt-get install open-cobol


コンパイルするソースは、http://www12.ocn.ne.jp/~peg/1_1.html#c10より。

       IDENTIFICATION DIVISION.
       PROGRAM-ID. hello.
       PROCEDURE DIVISION.
       DISPLAY "Hello World!".
       STOP RUN.

そしてコンパイル。

[xxx@/src/cobol]$ cobc -x hello.cob 
/tmp/cob2662_0.c: In function ‘hello_’:
/tmp/cob2662_0.c:75: warning: dereferencing type-punned pointer will break strict-aliasing rules
/tmp/cob2662_0.c:76: warning: dereferencing type-punned pointer will break strict-aliasing rules
/tmp/cob2662_0.c:77: warning: dereferencing type-punned pointer will break strict-aliasing rules
/tmp/cob2662_0.c:88: warning: dereferencing type-punned pointer will break strict-aliasing rules
/tmp/cob2662_0.c:107: warning: dereferencing type-punned pointer will break strict-aliasing rules
/tmp/cob2662_0.c:111: warning: dereferencing type-punned pointer will break strict-aliasing rules

ワーニングは出たのですが、

[xxx@/src/cobol]$ ls
hello  hello.cob

実行バイナリがあったので実行してみました。

[xxx@/src/cobol]$ ./hello
Hello World!

ちなみにcobcのman

OPEN-COBOL(1)                                                    OPEN-COBOL(1)

NAME
       open-cobol - COBOL compiler

SYNOPSIS
       cobc [options] files...
       cobcrun  program [ arguments to program ]

DESCRIPTION
       This manual page documents briefly the cobc and cobcrun commands.

       cobc is the COBOL compiler.

       cobcrun is a driver program to run COBOL programs compiled as modules.

OPTIONS
       The  cobc  program follows the usual GNU command line syntax, with long
       options starting with two  dashes  (`-').   A  summary  of  options  is
       included below.  For a complete description, see the Info files.

       -h, --help
              Show summary of options.

       --version
              Show version of program.

SEE ALSO
       info open-cobol
       http://www.opencobol.org/

AUTHOR
       open-cobol was written by Keisuke Nishida <knishida@netlab.jp>.

       This  manual  page  was  written  by  Bart Martens <bart.martens@adval‐
       vas.be>, for the Debian project (but may be used by others).

                                March  4, 2006                   OPEN-COBOL(1)

とhオプション

[xxx@/src/cobol]$ cobc -h
Usage: cobc [options] file...

Options:
  --help                Display this message
  --version, -V         Display compiler version
  -v                    Display the programs invoked by the compiler
  -x                    Build an executable program
  -m                    Build a dynamically loadable module (default)
  -std=<dialect>        Compile for a specific dialect :
                          cobol2002   Cobol 2002
                          cobol85     Cobol 85
                          ibm         IBM Compatible
                          mvs         MVS Compatible
                          bs2000      BS2000 Compatible
                          mf          Micro Focus Compatible
                          default     When not specified
                        See config/default.conf and config/*.conf
  -free                 Use free source format
  -fixed                Use fixed source format (default)
  -O, -O2, -Os          Enable optimization
  -g                    Produce debugging information in the output
  -debug                Enable all run-time error checking
  -o <file>             Place the output into <file>
  -b                    Combine all input files into a single
                        dynamically loadable module
  -E                    Preprocess only; do not compile, assemble or link
  -C                    Translation only; convert COBOL to C
  -S                    Compile only; output assembly file
  -c                    Compile and assemble, but do not link
  -t <file>             Generate and place a program listing into <file>
  -I <directory>        Add <directory> to copybook search path
  -L <directory>        Add <directory> to library search path
  -l <lib>              Link the library <lib>
  -D <define>           Pass <define> to the C compiler
  -conf=<file>          User defined dialect configuration - See -std=
  --list-reserved       Display all reserved words
  -save-temps           Do not delete intermediate files
  -MT <target>          Set target file used in dependency list
  -MF <file>            Place dependency list into <file>
  -ext <extension>      Add default file extension

  -Wall                 Enable all warnings
  -Wobsolete            廃要素が使われていれば警告する
  -Warchaic             古い仕様が使われていれば警告する
  -Wcolumn-overflow     72 桁を越えるテキストを警告する
  -Wredefinition        データ項目の再定義を警告する
  -Wconstant            不適切な定数を警告する
  -Wparentheses         OR と AND が括弧なしで並んでいれば警告する
  -Wterminator          終止符(END-XXX)がなければ警告する
  -Wstrict-typing       タイプの不適合を厳密に警告する
  -Wcall-params         Warn non 01/77 items for CALL params (NOT set with -Wall)
  -Wtruncate            Warn possible field truncation (NOT set with -Wall)

  -ftrace               トレースを出力に含める
  -fsyntax-only         文法チェックのみ。何も出力しない
  -fstatic-call         CALL 文で静的関数呼び出しを行なう
  -fdebugging-line      デバッグ行を有効にする
  -fsource-location     ソースの位置を出力に含める
  -fimplicit-init       Do automatic initialization of the Cobol runtime system
  -fline-directive      行情報を出力に含める
  -fstatic-linkage      Statically allocate non-USING LINKAGE parameters
  -fsign-ascii          Numeric display sign ASCII (Default on ASCII machines)
  -fsign-ebcdic         Numeric display sign EBCDIC (Default on EBCDIC machines)
  -fstack-check         PERFORM stack checking (Turned on by -debug or -g)
  -fnotrunc             Do not truncate binary fields according to PIC (ala MF)