I’ve been away from this project for several months and managed to forget exactly how I was supposed to invoke the COBOL compiler. I had made a note in the post
Installing gnuCOBOL on Windows, but that just tells where to find the compiler, not how to incorporate it into minGW.
I decided to incorporate gnuCOBOL into minGW again and document it for future use.
Download the Compiler
You can find the latest MinGW version at Arnold Trembley’s website. I want the version:
If this website goes away, the above file (which will go out of date quickly) can also be found here.
Install the Compiler
I assume you have already installed MinGW. My notes on doing so can be found here.
Arnold Trembley’s version of gnuCOBOL is configured to reside at c:\mingw\share. Therefore, create the directory c:\mingw\share, and unzip the contects of the gnuCOBOL zip file into it.
Add C:\MinGW\share\gnucobol\bin to your path.
This almost is done. There is one problem yet: the path will be setup to run GCC out of /mingw/bin and that will cause a problem (mingw’s gcc compiler will be unable to find <libcobol.h>. You need to run it out of /mingw/share/gnucobol/bin.
To do this you must edit /etc/profile and insert /mingw/share/gnucobol/bin as shown:
# My decision to add a . to the PATH and as the first item in the path list # is to mimick the Win32 method of finding executables. # # I filter the PATH value setting in order to get ready for self hosting the # MSYS runtime and wanting different paths searched first for files. if [ $MSYSTEM == MINGW32 ]; then export PATH=".:/mingw/share/gnucobol/bin:/usr/local/bin:/mingw/bin:/bin:$PATH" else export PATH=".:/usr/local/bin:/bin:/mingw/bin:$PATH" fi
To Test
Start minGW bash and type cobc -v
chiefdude10/~:cobc -v cobc (GnuCOBOL) 3.1-rc1.0 Built Jul 04 2020 17:17:54 Packaged Jul 01 2020 00:39:30 UTC C version (MinGW) "6.3.0" loading standard configuration file 'default.conf' cobc: error: no input files chiefdude10/~:
You should see the bold line above, indicating that the default configuration is loaded.
The same will work in CMD:
C:\>cobc -v cobc (GnuCOBOL) 3.1-rc1.0 Built Jul 04 2020 17:17:54 Packaged Jul 01 2020 00:39:30 UTC C version (MinGW) "6.3.0" loading standard configuration file 'default.conf' cobc: error: no input files C:\>
You now have a working gnuCOBOL compiler!
To test, I created the following file (there are 7 spaces before ‘>>SOURCE FREE’):
>>SOURCE FREE *> Sample COBOL program IDENTIFICATION DIVISION. PROGRAM-ID. hello. DATA DIVISION. PROCEDURE DIVISION. DISPLAY "Hello, world!". STOP RUN.
To compile and run:
C:\cobol\helloworld>cobc -x helloW.cob C:\cobol\helloworld>helloW Hello, world!