Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Generate interface to C function

218 views
Skip to first unread message

Walt Brainerd

unread,
Jun 27, 2014, 11:18:55 AM6/27/14
to
I would like to generate Fortran interfaces
to a large number of C functions in order to
use the ISO interop stuff. Does anybody know
of a tool that will help with this? Searching
these sacred texts produced nothing and Google
finds SWIG, which apparently creates interfaces
in almost every existing language except Fortran
(and probably Cobol). TIA.

Thomas Jahns

unread,
Jun 27, 2014, 11:56:26 AM6/27/14
to
One part of CDI[1] is a such generator. It still has some rough edges and we
haven't yet decided what to do about functions returning char * (it seems like
that will need some wrapping unless we simply return TYPE(c_ptr) and let the
caller deal with that) but if you'd like to have a starting point in Ruby try
interfaces/f2003/bindGen.rb from the tarball you can download via [2]. I think
there's some patches in VCS that aren't in the tarball, so if you like what you
see drop me a line (remove idontlikespam. to get a useful email address).

Thomas

[1] https://code.zmaw.de/projects/cdi
[2] https://code.zmaw.de/attachments/download/7201/cdi-1.6.3.tar.gz

Beliavsky

unread,
Jun 27, 2014, 12:34:43 PM6/27/14
to
I think I read that FGSL https://www.lrz.de/services/software/mathematik/gsl/fortran/ , the Fortran interface to the Gnu Scientific Library, was created in an automated manner. There was an article on FGSL in the August 2007 edition of SIGPLAN Fortran Forum which should explain how it was created.

Your question was asked on Stack Overflow http://stackoverflow.com/questions/8444584/automatic-generation-of-fortran-2003-bindings-from-c-library-headers-using-iso "Automatic generation of Fortran 2003 bindings from C library headers (using iso_c_bindings intrinsic module)", where someone suggested a python program cfwrapper.py .

Walt Brainerd

unread,
Jun 27, 2014, 5:43:25 PM6/27/14
to
Thanks for the information.

For some reason, I didn't renew the Fortran Forum some time ago :-(.
Years ago, it was mostly about standards and I pretty much knew all
about that then. Looks like some more interesting stuff in it these
days. But I guess I can't get to it now.

The cfwrapper.py is written specifically for GTK-Fortran, but there
are big chunks of it that I can steal, so that gives me a good start
toward creating my own version. So, that was very helpful.

John Harper

unread,
Jun 29, 2014, 6:13:57 PM6/29/14
to
Off-topic but this is the 2nd time today I have seen a reference to Cobol
after years with none. The 1st time was an item in this morning's paper that
our Inland Revenue is proposing to spend over a gigabuck of the taxpayers'
money it collects on updating its software - about 40,000,000 lines of Cobol
at present. I hate to think what might happen...

--
John Harper

Walt Brainerd

unread,
Jul 2, 2014, 3:54:02 PM7/2/14
to
This was posted because I am trying to "modernize" 1,000,000+
lines of Fortran, pretty much by myself. Isn't that just as
scary?

And I don't think I am being paid 1/40 of a gigabuck :-(.

James Van Buskirk

unread,
Jul 2, 2014, 6:43:42 PM7/2/14
to


"Walt Brainerd" wrote in message
news:Ka6dndGh9u7H_inO...@swcp.com...
Intel probably has such a tool because they translate stuff like
the Win32 API and OpenGL headers to Fortran modules. I wrote up
some Fortran to translate OpenGL headers to modules, but it was
kind of like �proceed to next error and write some more code to
get over it� rather than code intended to translate all possible
C headers to modules and wasn't even complete for its intended
purpose.

Walt Brainerd

unread,
Aug 8, 2014, 5:21:19 PM8/8/14
to
I just wanted to record for posterity that bindGen.rb was a big help in
generating interfaces to C functions. And thank Thomas for his help.

A couple of things had to be "fixed". There was no entry for C types
"short" and "long" (short int and long int were there)--easily fixed
with a couple of added lines. It does not like a space between the
function name and the ( beginning the parameter list. The parameter
declarations have to be within the parameter list, not afterward.

The code I had was written during the Bronze Age, so there were no
"modern" things to worry about, like structures.

It turns out that I can't yet use the C interop features, because
having the interfaces allows the compiler to catch a bunch of funny
things that seem to "work" anyway. But the interfaces have identified
many things that need to be fixed as the modernization progresses.
0 new messages