Generically Wrapping Fortran Library

I am interested in wrapping a Fortran library in Julia, but I find the name mangling a bit problematic for deploying to HPC environments where people may want to use a custom binary. The docs say:

“so to call a Fortran function you must pass the mangled identifier corresponding to the rule followed by your Fortran compiler”

My first reaction was ok I’ll use BinaryBuilder and that way the compiler will be consistent and I’ll know what the names of the functions to wrap are. Basically I just need to make sure BinaryBuilder is using a consistent gfortran (I just want linux).

However, this code links against libraries that could in theory be vendor specific like MPI and BLAS (think an HPC environment). If I want users to be able to use their custom compiled version of the fortran library I have no control over the compiler and therefore no control over the mangled names. Is this just something I will be unable to support?

Thanks!

You can detect the mangling scheme during your Pkg.build step, and use it to define something similar to the @blasfunc macro in LinearAlgebra.jl that does your name-mangling for you. You then use this macro in every ccall.

1 Like

You can also use the iso_c_binding Fortran library. The names won’t be mangled, then.

You can read more about it here: Interoperability with C (The GNU Fortran Compiler)

3 Likes