Compiling a windows (.exe) executable file using gnu cobol on ubuntu

Issue

I need a program I wrote in a .cobc file to be compiled to a windows executable file.
The file is called main.cobc
Compiling it with: cobc -x -free *.cobc -o main
makes it a linux executable which is ok, but can’t be run directly on windows.
I have gnucobol (OpenCOBOL installed on my linux ubuntu VM.
Please help. Is there a way I could compile it in a way that it’s windows compatible?

Thanks in advance!

Solution

Is there a way I could compile it [a COBOL source] in a way that it’s windows compatible?

That’s not the question that is in the title, so answering that first.
Can you do it from Ubuntu?
Yes, … as cobc uses an underlying C compiler and you can do cross-compiling with C compilers (you’ll likely use gcc-mingw-w64-i686 or gcc-mingw-w64-x86-64).

… but it needs a lot of set-up.

  • install the cross-compiler environment
  • get all the dependencies for cobc/libcob working in this environment
  • build and install a second version of the GnuCOBOL package from source using ./configure --host=i686-w64-mingw32
  • compile your programs using the mingw version of cobc

This way you get a "main.exe" which you can use on a Windows computer as long as you ship the mingw dll, libcob dll (and the dll files of all its dependencies).

I have gnucobol (OpenCOBOL installed on my linux ubuntu VM.
Please help. Is there a way I could compile it in a way that it’s windows compatible?

That’s the "long question". Yes, and very easy.
When you do have a Windows environment and want to generate an executable for that – no need for doing this in a separate VM (or WSL) in the first place, just get the official ready-to-use MinGW packages for GnuCOBOL (available for both 32 and 64bit) and compile directly on the Windows machine.

Answered By – Simon Sobisch

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published