OpenCOBOL 静态链接多个 .cob 文件

OpenCOBOL Static Linking Multiple .cob Files

我正在尝试按照此处列出的示例使用 GnuCobol (Windows 10) 将两个 COBOL 文件静态 link 在一起:https://open-cobol.sourceforge.io/historical/open-cobol/Static-Linking.html 但似乎无法使其正常工作。

我是运行以下的人:

cobc -free -c InterpFunc.cob
cobc -free -c -fmain Integrator.cob 
cobc -x -o .\dist\integrator Integrator.o InterpFunc.o

“.o”文件编译正确,但二进制文件从未构建并出现以下错误:

H:\Programs\COBAL\cobc\bin\cobc.exe: unrecognized option '-fmain'
h:/programs/cobal/cobc/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
The terminal process terminated with exit code: 1

我尝试了一些不同的方法,例如省略“-fmain”或省略“-x”,但似乎都会产生不同的错误。

这可能是我的 compiler/system 设置的问题,还是我误解了如何静态 link 文件?

我很确定您没有使用与旧文档相匹配的编译器(URL 中有 "historical")。我很确定它会像 current manual 所说的那样工作:

The easiest way of combining multiple files is to compile them into a single executable.

One way is to compile all the files in one command:

$ cobc -x -o prog main.cob subr1.cob subr2.cob

Another way is to compile each file with the option -c, and link them at the end. > The top-level program must be compiled with the option -x.

$ cobc -c subr1.cob
$ cobc -c subr2.cob
$ cobc -c -x main.cob
$ cobc -x -o prog main.o subr1.o subr2.o