在 Windows 上使用 GnuCOBOL 解决 MinGW 错误

问题描述 投票:0回答:1

我不确定这是否是 MinGW 问题,或者 GnuCOBOL 的

cobc
调用 C 编译器的方式是否存在问题。我已经浏览了手册,但我没有看到任何内容表明我在这里做错了什么。当然,这并不意味着我不是,但如果我是,我也没有意识到。

系统信息

我正在使用 Windows 11 Pro。

我通过 chocolatey 安装了 GnuCOBOL。这是

cobc --version
的输出:

cobc (GnuCOBOL) 3.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart
Built     Jul 28 2023 19:10:09
Packaged  Jul 28 2023 17:02:56 UTC
C version (MinGW) "9.2.0"

我还安装了 chocolatey 的 C 编译器,这是

gcc --version
的输出:

gcc.exe (x86_64-posix-seh-rev0, Built by MinGW-Builds project) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我正在 VS Code 中进行编辑,但没有使用任何扩展,并且我正在尝试从 Powershell 会话进行编译。出于所有意图和目的,我还不如在记事本中进行编辑。

代码

我正在尝试编译这个简单的程序:

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
DATA DIVISION.
    WORKING-STORAGE SECTION.
        77 X PIC 99.
        77 Y PIC 99.
        77 Z PIC 99.
PROCEDURE DIVISION.
    SET X TO 10.
    SET Y TO 25.
    ADD X Y GIVING Z.
    DISPLAY "X + Y = "Z.
STOP RUN.

你们中的一些人可能会从 JDoodle 中认出它是默认的示例 COBOL 程序,并且它在那里可以正常编译和运行;这是从 JDoodle 运行时的输出:

X + Y = 35

问题

但是,当我尝试在与

cobc -x hello.cbl
相同的目录中运行
hello.cbl
时,我看到:

hello.cbl:1: note: free format detected
    1 > IDENTIFICATION DIVISION.
    2 | PROGRAM-ID. HELLO-WORLD.
    3 | DATA DIVISION.
In file included from C:/ProgramData/mingw64/mingw64/x86_64-w64-mingw32/include/crtdefs.h:10,
                 from C:/ProgramData/mingw64/mingw64/x86_64-w64-mingw32/include/stddef.h:7,
                 from C:/ProgramData/mingw64/mingw64/lib/gcc/x86_64-w64-mingw32/13.2.0/include/stddef.h:1,
                 from C:\ProgramData\chocolatey\lib\gnucobol\tools\include/string.h:53,
                 from C:\Users\[REDACTED]\AppData\Local\Temp\cob20568_0.c:8:
C:/ProgramData/mingw64/mingw64/x86_64-w64-mingw32/include/corecrt.h:35:18: error: expected ';' before 'typedef'
   35 | __MINGW_EXTENSION typedef unsigned __int64 size_t;
      |                  ^~~~~~~~
      |                  ;
C:/ProgramData/mingw64/mingw64/x86_64-w64-mingw32/include/corecrt.h:45:18: error: expected ';' before 'typedef'
   45 | __MINGW_EXTENSION typedef __int64 ssize_t;
      |                  ^~~~~~~~
      |                  ;
C:/ProgramData/mingw64/mingw64/x86_64-w64-mingw32/include/corecrt.h:63:18: error: expected ';' before 'typedef'
   63 | __MINGW_EXTENSION typedef __int64 intptr_t;
      |                  ^~~~~~~~
      |                  ;
C:/ProgramData/mingw64/mingw64/x86_64-w64-mingw32/include/corecrt.h:76:18: error: expected ';' before 'typedef'
   76 | __MINGW_EXTENSION typedef unsigned __int64 uintptr_t;
      |                  ^~~~~~~~
      |                  ;
C:/ProgramData/mingw64/mingw64/x86_64-w64-mingw32/include/corecrt.h:89:18: error: expected ';' before 'typedef'
   89 | __MINGW_EXTENSION typedef __int64 ptrdiff_t;
      |                  ^~~~~~~~
      |                  ;
C:/ProgramData/mingw64/mingw64/x86_64-w64-mingw32/include/corecrt.h:124:18: error: expected ';' before 'typedef'
  124 | __MINGW_EXTENSION typedef __int64 __time64_t;
      |                  ^~~~~~~~
      |                  ;

我确实进入了

corecrt.h
并确认
__MINGW_EXTENSION typedef...
的每个实例确实存在。我尝试将这六行更正为
__MINGW_EXTENSION; typedef...
,但我没有更改任何其他内容。

进行更改后,我再次尝试运行

cobc -x hello.cbl
,这次得到:

hello.cbl:1: note: free format detected
    1 > IDENTIFICATION DIVISION.
    2 | PROGRAM-ID. HELLO-WORLD.
    3 | DATA DIVISION.
C:/ProgramData/mingw64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find /LIBPATH:C:\ProgramData\chocolatey\lib\gnucobol\tools\lib\libcob.lib: Invalid argument
collect2.exe: error: ld returned 1 exit status

我是一名专业开发人员,但我完全没有 C 编程经验。我只是为了好玩而尝试熟悉 COBOL。显然,我遇到了一些 C 编译器问题,但是我无法在网上找到任何特定于 GnuCOBOL 或我安装的特定版本 MinGW 的内容。我找到了大量常规 C 调试建议,但我不确定如何(或者我是否应该)将该指南应用于我已安装的 MinGW 版本。当我发现自己正在调试该包内部的文件时,我觉得我已经完全偏离了正轨。

这里还有其他人看到过这个问题吗?如果有的话有什么指导吗?

另外,在尝试 C 之前我不应该尝试 COBOL 吗?

我现在计划只使用 JDoodle,但如果可能的话,我希望在本地工作。

mingw cobol mingw-w64 gnucobol
1个回答
0
投票

choco 包包含 GCC(测试过的版本),您不需要“额外”安装它。确保它的“bin”目录位于路径中,并且找到并使用了 GCC(如果您不需要 choco GCC,否则我建议卸载它=)

理论上,choco 包应该“正常工作”,但是在 GnuCOBOL 讨论论坛中至少讨论了一个关于链接的问题,其中指出您可能需要在安装后调整 COB_LIBS

COB_LIB_PATH
(因为choco 包中的错误)。

© www.soinside.com 2019 - 2024. All rights reserved.