简体   繁体   中英

Compiling COBOL as 32-bit Executable For Windows

I am diving into the world of COBOL and have written a simple program that compiles and runs as intended from my KDE Plasma command line using open-cobol (cobc). I have seen a few sites mention that COBOL is quite portable and does not require multiple compilations, but when I try to run the same output program on Windows 10 (ie 32-bit), the system states that the program is a 16-bit application and thus cannot run.

Are there parameters that I can use with cobc to compile in such a way that my programs will run on Windows 10, or am I fundamentally misunderstanding the portability of this language?

Compilation command: cobc -x -o program program.cob

Your program is likely already a 64bit executable (depending on your actual OS, otherwise its 32bit), but it is definitely no Windows binary (and because Windows doesn't recognize it, it just guesses this is a 16bit executable).

COBOL itself is portable, even between different compilers ( if you restrict yourself to "standard" COBOL or use only the extensions that the compilers used share), but you need "some" native parts in any case. As a well known example take Java or .NET: the "runtime" is a native binary, which executes the java (or msil) byte code.

There are some COBOL compilers generating intermediate code which is actually portable and can be used with the "native runtime" you have to install beforehand.

The easiest option for your case: take a compatible compiler and recompile your COBOL source for this platform on this platform. I'd suggesting the successor of OpenCOBOL: GnuCOBOL , using the official windows binaries .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM