I'm trying to practice a C program (hello.c) calling cobol program (say.cob) from the manual gnucobol.
---- 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
I can see cob-config is present in gnucobol folder. And in environment variables COB_CONFIG_DIR %COB_MAIN_DIR%\config
what could be the problem? any help please?
cob-config
would need to be an executable script, which it commonly is. As you specify windows paths I assume you use that - and this one cannot run shell scripts. You may get around that with and additionalcob-config.bat
that executes this shell script, but In this case it will output mingw/wsl/cygwin/... paths that likely cannot be used in the Windows gcc.Solutions:
cob-config
as an executable script in$PATH
cobc
's feature to call the C processor (and if wanted also the linker) for you:cobc -c hello.c