Hi! I'm trying to make a Fortran 77 wrapper for C++ code. I have not found information about it. The idea is to use from functions from a lib that is written in C++ in a Fortran 77 progran.
Does anyone know how to do it? Thanks!
Hi! I'm trying to make a Fortran 77 wrapper for C++ code. I have not found information about it. The idea is to use from functions from a lib that is written in C++ in a Fortran 77 progran.
Does anyone know how to do it? Thanks!
Calling Fortran from C is easy, C from Fortran potentially tricky, C++ from Fortran may potentially become ... challenging.
I have some notes elsewhere. Those are quite old, but nothing changes very rapidly in this sort of area, so there may still be some useful pointers there.
Unfortunately, there's no really standard way of doing this, and different compilers may do it slightly different ways. Having said that, it's only when passing strings that you're likely to run into major headaches. The resource above points to a library called CNF which aims to help here, mostly by providing C macros to sugar the bookkeeping.
The short version, however is this:
foo
into _foo
or foo_
or some other variant (see the compiler docs).That's the majority of what you need to know. The rest is annoying detail, and making friends with your compiler and linker docs. You'll end up knowing more about linkers than you probably wanted to.
Lawrence Livermore National Laboratory developed a tool called Babel for integrating software written in multiple languages into a single, cohesive application. If your needs are simple you can probably just put C wrapper on your C++ code and call that from Fortran. However, if your needs are more advanced, it might be worth giving Babel a look.