我正在尝试练习从手册 gnucobol 调用 cobol 程序 (say.cob) 的 C 程序 (hello.c)。
---- say.cob ------
IDENTIFICATION DIVISION.
PROGRAM-ID. say.
ENVIRONMENT DIVISION.
DATA DIVISION.
LINKAGE SECTION.
01 HELLO PIC X(6).
01 WORLD PIC X(6).
PROCEDURE DIVISION USING HELLO WORLD.
DISPLAY HELLO WORLD.
EXIT PROGRAM.
---- hello.c -
#include <libcob.h>
extern int say(char *hello, char *world);
int
main()
{
int ret;
char hello[7] = "Hello ";
char world[7] = "World!";
cob_init(0, NULL);
ret = say(hello, world);
return ret;
}
C:\Users\S M Rao>gcc -c ‘cob-config --cflags‘ hello.c
gcc: error: `cob-config: No such file or directory
gcc: error: unrecognized command line option '--cflags`'
if I run with commands
cobc -c hello.c
cobc -c -static say.cob
cobc -x -o hello hello.o say.o
getting following error
C:\Users\S M Rao>cobc -x -o hello hello.o say.o
hello.o:hello.c:(.text+0x5c): undefined reference to `say'
collect2.exe: error: ld returned 1 exit status
我可以看到 cob-config 存在于 gnucobol 文件夹中。并在环境变量 COB_CONFIG_DIR %COB_MAIN_DIR%\config
可能是什么问题?有什么帮助吗?
最佳答案
cob-config
需要是一个可执行脚本,通常是这样。
当您指定 Windows 路径时,我假设您使用该路径 - 并且该路径无法运行 shell 脚本。您可以使用执行此 shell 脚本的附加 cob-config.bat
来解决这个问题,但在这种情况下,它将输出 mingw/wsl/cygwin/... 路径这可能无法在 Windows gcc 中使用。
解决方案:
- 在匹配的 shell 中运行 gcc,而不是从 Windows 端运行,并将
cob-config
作为$PATH
中的可执行脚本 - 使用
cobc
的功能为您调用 C 处理器(如果需要,还可以调用链接器):cobc -c hello.c
关于cobol - gnucobol 海湾合作委员会 : error: `cob-config: No such file or directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67107460/