OpenCOBOL静态链接多个.cob文件

时间:2019-02-14 00:35:55

标签: windows compiler-errors compilation cobol gnucobol

我正在尝试按照此处列出的示例使用GnuCobol(Windows 10)将两个COBOL文件静态链接在一起: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',但似乎都产生了不同的错误。

这可能是我的编译器/系统设置存在问题吗?还是我误解了如何静态链接文件?

1 个答案:

答案 0 :(得分:3)

我非常确定您不会使用与该旧文档相匹配的编译器(其URL中具有“历史性”)。我非常确定它可以像current manual所说的那样工作:

  

组合多个文件的最简单方法是将它们编译为单个可执行文件。

     

一种方法是在一个命令中编译所有文件:

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

另一种方法是使用-c选项编译每个文件,并在最后链接它们。 >必须使用-x选项编译顶层程序。

$ cobc -c subr1.cob
$ cobc -c subr2.cob
$ cobc -c -x main.cob
$ cobc -x -o prog main.o subr1.o subr2.o
相关问题