Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Can anybody explain me how to compile and run a COBOL program in Ubuntu? I have never written any program in Ubuntu. Please, give me a simple program to compile and run.

share|improve this question
    
COBOL is a language I've been trying to forget for quite some time. I once did get a job because I was the only FORTRAN IV programmer they could find who was willing to learn COBOL. LOL. Although programs in COBOL "can" be written to be very readable, it's underlying data structures, flow control, and type conversions can be a nightmare. If you find something you really need in COBOL, use it, but don't write anything new in it unless you have no choice! –  Joe May 2 '13 at 4:59
add comment

3 Answers

COBOL is not particularly popular on Linux but there are compilers available. One of these is open-cobol.

First step is to check if it's installed on your system: it probably isn't.

whereis cobc; which cobc
cobc:

If like my system it is not installed you can install it with

sudo apt-get install open-cobol

And to check its installed whereis cobc; which cobc

cobc: /usr/bin/cobc /usr/bin/X11/cobc /usr/share/man/man1/cobc.1.gz
/usr/bin/cobc

Now lets write our first program with any text editor.

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
* simple hello world program
PROCEDURE DIVISION.
    DISPLAY 'Hello world!'.
    STOP RUN.

save this as "helloworld.cbl"

We can now compile it with cobc -free -x -o helloworld helloworld.cbl

On my system I see this

$ cobc -free -x -o helloworld helloworld.cbl
/tmp/cob3837_0.c: In function ‘HELLO_2DWORLD_’:
/tmp/cob3837_0.c:75:7: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
/tmp/cob3837_0.c:76:7: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
/tmp/cob3837_0.c:77:7: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
/tmp/cob3837_0.c:88:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
/tmp/cob3837_0.c:107:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
/tmp/cob3837_0.c:111:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

A few warnings -- but no errors test with ./helloworld

Hello World!

It works.


Taken from:

Cobol Hello World Example: How To Write, Compile and Execute Cobol Program on Linux OS on thegeekstuff.com

Tested on Ubuntu 12.04.2

share|improve this answer
1  
Seeing this made a grey-haired geek happy. –  Bobble May 1 '13 at 7:53
add comment

You can use the open-cobol compiler. Just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command below:

sudo apt-get install open-cobol
cobc your_program_here.cbl 
share|improve this answer
add comment

Warren Hill gave a good answer. You can also use an IDE such as Eclipse to help with COBOL but I'm not sure that's appropriate if you have never programmed.

See the Eclipse COBOL forum, Eclipse Forums

I noticed one of the posts lists available COBOL plug-ins...

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.