インターネット&PC120%活用:PC活用編

TinyCobolのインストール

TinyCobolはなかなかよくできたCOBOLです。Linux用とCygwin用が用意されています。
インストールは少々面倒(特にCygwin環境の構築がやや厄介かも)ですが、CUIのCOBOLを使いたい人は
頑張ってみて下さい。以下に、Cygwin版のインストールについてまとめてみました。


0 Cygwinのインストール
Cygwinのインストールについては、「Cygwinインストール」を参照して下さい。

1 TinyCobolのインストール

まず、 http://tiny-cobol.sourceforge.net/snapshots.html から,
@ db-1.86-1.cygwin.tar.gz
A getopt-1.0.3.cygwin.tar.gz
B tinycobol-0.58-1.cygwin.zip
をダウンロードして下さい。
2004年1月の時点で、TinyCobolの最新バージョンは0.61ですが、おじさんのCygwin環境ではコンパイル途中で
エラーがでて、正常に動作しませんでした。0.58では動作確認できました。

tinycobol-0.58-1.cygwin.zip はZIPファイルなので、解凍してください。
Cygwin上で解凍するなら
$unzip c:/temp/tinycobol-0.58-1.cygwin.zip でできます。
解凍すると、C tinycobol-0.58-1.cygwin.tar.gz というファイルができます。
次に上記@、AのファイルとこのCのファイルのインストールをします。インストールはCygwinのsetup.exeを使う
のが一番簡単だと思います。

おじさんはCygwin上でLinuxコマンドでインストールしましたので、その手順を以下にあげておきます。
おじさんの場合は、上記の3つのファイルはFドライブにダウンロードしてあります。@のdb-1.86-1.cygwin は
おじさんのCygwin環境にインストール済みだったので、以下ではインストールしてません。
*Cygwinの説明やLinuxのコマンドについてはここでは説明省略します。
 tarコマンドについてはLinuxコマンド集 tarをご覧下さい。

Owner@tsuyoshi /cygdrive/f
$ tar xvzf tinycobol-0.58-1.cygwin.tar.gz -C /
usr/bin/htcobol.exe
usr/local/lib/libhtcobol.a
usr/local/share/htcobol/
usr/local/share/htcobol/htcobolrc
usr/local/share/htcobol/htcobolpp.exe
usr/local/share/htcobol/copybooks/
usr/local/share/htcobol/copybooks/screen.cpy
usr/local/share/htcobol/htcobolrc-0.58
usr/doc/tinycobol-0.58-1/
usr/doc/tinycobol-0.58-1/COPYRIGHT
usr/doc/tinycobol-0.58-1/ANNOUNCE
usr/doc/tinycobol-0.58-1/COPYING.LIB
usr/doc/tinycobol-0.58-1/COPYING
usr/doc/tinycobol-0.58-1/htcobol_man.html
usr/doc/tinycobol-0.58-1/htcobol_man_en.html
usr/doc/tinycobol-0.58-1/htcobol_man_es.html
usr/doc/tinycobol-0.58-1/htcobol_man_fr.html
usr/doc/tinycobol-0.58-1/htcobol_man_it.html
usr/doc/tinycobol-0.58-1/htcobol_man_pt_BR.html
usr/doc/tinycobol-0.58-1/htcobolpp_man.html
usr/doc/tinycobol-0.58-1/htcobolpp_man_en.html
usr/doc/tinycobol-0.58-1/htcobolpp_man_es.html
usr/doc/tinycobol-0.58-1/htcobolpp_man_fr.html
usr/doc/tinycobol-0.58-1/htcobolpp_man_it.html
usr/doc/tinycobol-0.58-1/htcobolpp_man_pt_BR.html
usr/doc/tinycobol-0.58-1/INSTALL
usr/doc/tinycobol-0.58-1/INSTALL.Win32
usr/doc/tinycobol-0.58-1/README
usr/doc/tinycobol-0.58-1/ChangeLog

Owner@tsuyoshi /cygdrive/f
$ tar -zxvf getopt-1.0.3.cygwin.tar.gz -C /
usr/local/lib/libgnugetopt.a
usr/local/include/gnugetopt.h
usr/doc/getopt-1.0.3-1/
usr/doc/getopt-1.0.3-1/COPYING
usr/doc/getopt-1.0.3-1/Changelog
usr/doc/getopt-1.0.3-1/getopt.1
usr/doc/getopt-1.0.3-1/getopt-1.0.3.lsm
usr/doc/getopt-1.0.3-1/README
usr/doc/getopt-1.0.3-1/TODO

...........途中略 /usr/src/htcobolというディレクトリ作成.......

Owner@tsuyoshi /cygdrive/f
$ cd /usr/src/htcobol
Owner@tsuyoshi /usr/src/htcobol
$ htcobol -V
TinyCOBOL - pre alpha 0.58.0 (released on 2002/06/04)
(C) 1991, 1993, 1999-2002 Rildo Pragana et. al.
<--Fドライブのルートにいます
tarで展開 オプション -C / をつけ
ないとFドライブに展開されてしまうの
で注意して下さい。
tarコマンドのオプションのxvzfは「gzファイルを展開し、処理したファイルの一覧を詳細に表示する」という動作になります。


























getoptの展開













htcobol起動
-V オプションで、バージョン表示
この表示がでれば、とりあえず正常
にインストールできている

(-h でヘルプ表示することができる)


2 "Hello World"のコンパイル
インストールが完了したら、"Hello World"というおなじみのプログラムをコンパイルして実行してみましょう。
以下がソースファイル(test.cob)です。

* hello.cob : 
IDENTIFICATION  DIVISION.
PROGRAM-ID.     HELLO.
ENVIRONMENT     DIVISION.
DATA            DIVISION.
PROCEDURE       DIVISION.
DISPLAY 'HELLO WORLD!!'.
   STOP RUN.

では、コンパイルして実行してみます。このtest.cobは、/usr/src/htcobol に作成してあります。
コンパイラの名前はhtcobolです。コンパイル時の書式は
htcobol [option] sorce_filename
です。指定できるオプション(option)は、以下に載せておきます。

コンパイルと実行画面

Owner@tsuyoshi /usr/src/htcobol
$ ls
test.COB

Owner@tsuyoshi /usr/src/htcobol
$ htcobol -v test.COB
/usr/local/share/htcobol/htcobolpp -v -t 8 -x test.COB -o test.i
as.exe -o test.o test.s
gcc.exe -o test test.o -L/usr/local/lib -lhtcobol -lm

Owner@tsuyoshi /usr/src/htcobol
$ ls
test.COB  test.exe

Owner@tsuyoshi /usr/src/htcobol
$ ./test
HELLO WORLD!!

Owner@tsuyoshi /usr/src/htcobol
$


lsコマンドでソース確認



コンパイル
-v オプションをつけると、コンパイラの処理を詳細に表示します。








実行




ということで、コンパイル、実行までひとまず成功です。
参考までに、TinyCobol(htcobol)のコンパイル時のオプションを掲載しておきます。


Usage: htcobol [options] file
Compiler specific options:
-h Help (display this listing)
-a Create static library; Preprocess, compile, assemble and archive
-B <mode> Specify libraries binding mode ( static or dynamic )
-c Preprocess, compile and assemble, but do not link
-E Output preprocessor to standard output only; do not compile, as
semble or link
-g Generate compiler debugging output
-l <name> Add library name to link step
-L <dir> Add directory to library search path
-m <name> Create shared library; Preprocess, compile, assemble and link
-n Don't actually run any commands; just print them
-o <file> Specify output file name
-S Preprocess, compile (generate assembler code) only; do not asse
mble or link
-v Generate verbose compiler output
-V Display compiler version information and exit
-Wl,<options> Pass comma-separated <options> on to the linker
-x Create executable; Preprocess, compile, assemble and link
-z Generate very verbose compiler output
COBOL specific options:
-C Make all COBOL calls dynamic
-D Include COBOL source debugging lines
-F Input source is in standard fixed column format
-I <dir> Add directory to the end of the include (copybooks) search paths
-P Generate output listing file
-T <num> Expand tabs to number of space(s) (default T=8)
-X Input source is in free format (default format)


Cobolの説明も、CygwinやLinuxコマンドについての説明もほとんど省略してしまったので、それぞれに
についての基礎知識がないとわかりにくい点もあったかと思います。説明いれるとかなりの分量になって
しまうので、インストールととりあえずコンパイルの手順の説明だけに絞りました。

TopPage


inserted by FC2 system