LoginSignup
9
5

More than 5 years have passed since last update.

Mac 上の opensource COBOL で Hello World!!

Posted at

OSSコンソーシアムオープンCOBOLソリューション部会が提供する opensource COBOL をMacにインストールして、「Hello World!!」を出力するCOBOLプログラムをコンパイル・動作させます。

opensource COBOL のインストール

opensource COBOL のダウンロードサイトからUTF-8のソースパッケージ(2017年2月8日時点ではopensource-cobol-1.5.1J-utf8.tar.gz)をダウンロードします。

また、opensource COBOL に必要なGMPのソースパッケージ(2017年2月8日時点ではgmp-6.1.2.tar.lz)もダウンロードします。

インストールはGMPから始めますが、その前にGMPのlzip圧縮されたソースパッケージを展開するためのツールをbrew経由でインストールします。

$ brew install plzip

GMPのソースパッケージを展開し、コンパイル、インストールします。

$ plzip -d gmp-6.1.2.tar.lz
$ tar xf gmp-6.1.2.tar
$ cd gmp-6.1.2
$ ./configure
$ make
$ sudo make install

次に opensource COBOL に必要な Berkeley DB をbrew経由でインストールします。

$ brew install berkeley-db

最後に opensource COBOL をコンパイル、インストールします。

$ cd ..
$ tar zxf opensource-cobol-1.5.1J-utf8.tar.gz
$ cd opensource-cobol-1.5.1J-utf8
$ ./configure
$ make
$ sudo make install

COBOLプログラムの作成と実行

ソースファイル hello.cob に以下のとおりコーディングします。コードの各行は8桁目から始まっていることに注意してください。

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

コンパイルして実行します。

$ cobc -x hello.cob
$ ./hello
Hello World!!
9
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
5