Monday, July 13, 2015

Cobol programming language - Install openCOBOL

What is COBOL
COBOL (Common Business Oriented Language) was the first widely-used high-level programming language for business applications.
COBOL is used for writing application programs and we cannot use it to write system software. 


COBOL is a standard language that can be compiled and executed on machines such as IBM AS/400, personal computers, etc.
 

It was designed for business-oriented applications related to financial domain, defense domain, etc. It can handle huge volumes of data because of its advanced file handling capabilities.
 

Logical control structures are available in COBOL which makes it easier to read and modify. COBOL has different divisions, so it is easy to debug.

What is OpenCOBOL

OpenCOBOL is an open-source COBOL compiler. OpenCOBOL implements a substantial part of the COBOL 85 and COBOL 2002 standards, as well as many extensions of the existent COBOL compilers.

OpenCOBOL translates COBOL into C and compiles the translated code using the native C compiler. You can build your COBOL programs on various platforms, including Unix/Linux, Mac OS X, and Microsoft Windows. cobc binaries exist for HP/UX, zOS, SPARC, RS6000, AS/400 and more.

The compiler is licensed under GNU General Public License.
The run-time library is licensed under GNU Lesser General Public License.


More information: http://www.opencobol.org

Install procedure:

I have done the installation on a virtual server with RHEL 7.1 64 bits and root as user.

1) Download software
$ wget http://downloads.sourceforge.net/project/open-cobol/gnu-cobol/1.1/gnu-cobol-1.1.tar.gz

2) Unzip file
$ tar zxvf gnu-cobol-1.1.tar.gz

Note: In RHEL 7.1 you must have installed the following libraries

GNU MP (libgmp) 4.1.2 or later
    libgmp is used to implement decimal arithmetic.
    GNU MP is licensed under GNU Lesser General Public License.

GNU Libtool (libltdl)
    libltdl is used to implement dynamic CALL statements.
    GNU Libtool is licensed under GNU Lesser General Public License.


If you have not installed then:
$ yum install gmp-devel libtool 

3) Configure and install
$ cd gnu-cobol-1.1
$ ./configure

$ make
$ make install

Note: if you get the following error "configure: error: Berkeley DB db.h is missing or has incompatible version"

$ yum install libdb-devel.x86_64


4) Test cobol compiler
$ cobc -V

cobc (GNU Cobol) 1.1.0
Copyright (C) 2001,2002,2003,2004,2005,2006,2007 Keisuke Nishida
Copyright (C) 2006-2012 Roger While
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Built     Jul 08 2015 13:37:40
Packaged  Jan 20 2014 07:40:53 UTC
C version "4.8.3 20140911 (Red Hat 4.8.3-9)"


5) Create a test file
$ vi myFirstCob.cob

IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE-01.
ENVIRONMENT DIVISION.
DATA DIVISION.
PROCEDURE DIVISION.
MAIN.
DISPLAY "My First COBOL" UPON CONSOLE. |
STOP RUN.
 

$ cobc -x -free myFirstCob.cob
$ ./myFirstCob

Note:

./myFirstCob: error while loading shared libraries: libcob.so.1: cannot open shared object file: No such file or directory

It'll add the libcob.so to LD_LIBRARY_PATH

$ vi /etc/ld.so.conf.d/gnu-cobol-1.1.conf
Write the following:
/usr/local/lib

$ ldconfig

Run again sample program.

$ ./myFirstCob





1 comment: