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.
Alternative (fixed format):
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
* simple hello world program
PROCEDURE DIVISION.
DISPLAY 'Hello world!'.
STOP RUN.
save this as "helloworld.cob" and compile it with cobc helloworld.cob
(run with cobcrun helloworld
.
If you want to remove the warnings from the C compiler: download a current GnuCOBOL 2.x snapshot (which has no updated package yet) and build it yourself (needs an additional apt-get bison flex libdb-dev curses-dev
).
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
Advice
First of all, you don't have to settle for no IDE. Install Eclipse, it's available in the Ubuntu Software Centre. You also want to install CDT for Eclipse which gives you C/C++ support. Second I'd very much advise you to focus on C++ and Qt instead of C and GTK. Qt is a great cross-platform framework that uses C++ and QML (a JavaScript-like language for UI), and Ubuntu is moving more and more towards using Qt for their future desktop and mobile development. These tools will allow you not only to create beautiful applications for Ubuntu desktop but also for Android, Windows, Mac, BlackBerry and other OSes. An excellent Qt-specific IDE is QtCreator, also available in the Ubuntu Software Center, you should check it out along some Qt tutorials.
Answer
To answer you question directly, even though I strongly recommend doing what I outlined above, you likely need the -dev versions of the libraries you use. For GTK 3, you likely have to:
sudo apt-get install libgtk-3-dev
That should get you all GTK 3 headers.
Best Answer
You need to compile your program before you can run it. To do this, you'll need a C compiler, like
gcc
. You can install this with:Then, to compile your program, creating an executable called
file
:Which you should then be able to run: