I do apologise in advance. I only discovered this forum after raising an issue on the project. I am a pretty new c programmer so its possible it is a user issue, but I am really stuck and looking for advice.
In summary, trying to use libffi. Setting a reference to a libffi value stops the cobol program from finding the entry point of the c module.
say.c
#include<stdio.h>#include<ffi.h>intsay(char*hello,char*world){intnum_dgs=1;ffi_type*args[num_dgs];args[0]=&ffi_type_uint32;// This line causes issue. If commented out, it finds the entry point.printf("Got to end\n");return(0);}
Receive error libcob: error: entry point 'say' not found
I have the COB_LIBRARY_PATH set to .
The strange thing is, this works fine on MacOS where I do much of my dev. It seems to be an issue on Linux.
The difference there is it used dylib instead of so files, but otherwise the same.
Anyhow, any advice or help would be much appreciated.
Thanks!
Anthony
If you comment the libffi call out then the module can be loaded, if you don't then you need it, otherwise it isn't possible to load the module.
Note: you don't need to use your native C compiler if you want to create C modules that are used for COBOL the easiest option is to use cobc for that.
This leads to either:
cobc-x-ohellohello.cob
cobc-m-osay.sosay.c-lffi
or, because "output file from input file default"
cobc-xhello.cob
cobc-msay.c-lffi
or one fat binary as serge noted:
cobc-lffi-xhello.cobsay.c
Note: depending on your linker defaults this may not work and need to either use an additional -Q '-Wl, --no-as-needed' option or a change to CALL STATIC 'say'.
In any case it is a good thing to explicit define "external" entry points as those - in your case extern int say.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I do apologise in advance. I only discovered this forum after raising an issue on the project. I am a pretty new c programmer so its possible it is a user issue, but I am really stuck and looking for advice.
See [bugs:#833]
In summary, trying to use libffi. Setting a reference to a libffi value stops the cobol program from finding the entry point of the c module.
say.c
hello.cob
compile and run
Receive error
libcob: error: entry point 'say' not foundI have the COB_LIBRARY_PATH set to .
The strange thing is, this works fine on MacOS where I do much of my dev. It seems to be an issue on Linux.
The difference there is it used dylib instead of so files, but otherwise the same.
Anyhow, any advice or help would be much appreciated.
Thanks!
Anthony
Related
Bugs:
#833Last edit: Simon Sobisch 2022-06-18
Hi.
have you tried : cobc -x -o hello.cob say.c -lffi
Hope it helps.
If you comment the libffi call out then the module can be loaded, if you don't then you need it, otherwise it isn't possible to load the module.
Note: you don't need to use your native C compiler if you want to create C modules that are used for COBOL the easiest option is to use
cobcfor that.This leads to either:
or, because "output file from input file default"
or one fat binary as serge noted:
Note: depending on your linker defaults this may not work and need to either use an additional
-Q '-Wl, --no-as-needed'option or a change toCALL STATIC 'say'.In any case it is a good thing to explicit define "external" entry points as those - in your case
extern int say.THANKS!.. That was simple. I am not sure why on MacOS it behaves differently but I guess that's just the way things are. Thanks again!
The outline above works on every system, including MacOS and Win32.