Is there any (easy) working utility to generate Fortran interfaces, using iso_c_binding module, for a set of C prototypes, say placed in a C header file?
I have googled and found
bindGen.rb - Ruby script in CDI package, does not seem to process my header
h2m - I am unable to build it (it seems to require clang and llvm)
cfwrapper.py by @vmagnin in gtk-fortran - this seems to be for gtk libraries only?
Yes, it was specifically developed to generate Fortran interfaces for GLib/GTK. You could of course hack it for other C libraries, but would have to finely tweak the code, especially the regular expressions. It depends on the complexity of the header files; the wrapper makes a first pass to clean the C preprocessor stuff before looking for C prototypes.
I had already encountered such a syntax at the beginning of the project without understanding what it meant. That’s again a preprocessor trick: if you define a macro with that same name g_str_has_suffix, the preprocessor won’t make the substitution here because of the parentheses.
Of course, my wrapper “thought” that the name of the function was gboolean. I have refactored that part of the code and tune the regexes. Now, the analysis starts from the end of the line: the first parentheses pair (from right) is then the arguments of the function, then you have the name (possibly in parentheses), then the returned type.
CBFortran (“fork” of CodeBlocks) or just CodeBlocks with “FortranProject” extension installed has some feature like described in tutorial: BindTo User Guide | CBFortran
If you tell me the name of the library or if you send me the header files, I could try to use my cfwrapper on it. No guarantee, but if the prototypes are clear, we could expect a good result (partial or full).
FWIW, ChatGPT (specifically, GPT-4) does a surprisingly reasonable job generating Fortran interfaces and test code to call C functions (at least a few that I tried). I guess this question is asked often enough to provide lots of training material for it.