[Mono-list] Need advice about Mono C# + MinGW Fortran

Robert Dodier robert.dodier at gmail.com
Sun Mar 4 01:04:41 UTC 2018


I am interested in puzzling out how to call a Fortran function from C#
on Windows. I was inspired by a question about how to get a certain
function (complex Bessel function) in C#. One way would be link a C#
program with SLATEC, which provides many math functions and is written
in Fortran.

I am working on Linux, so I am attempting this with Wine + MinGW
compilers. I have succeeded in compiling and running a Fortran program
with that combo. I have also succeeded with compiling and running a C#
program using Mono C# compiler.

Now I am trying to link a C# and DLL created from a Fortran function.
Has anyone succeeded there? Linking C# with a DLL created from a C
function would probably point me in the right direction also.

I have been trying to use some notes about linking C# and Fortran on
Windows, and trying to adapt those instructions to Wine. My most
recent attempt yields the following:

$ wine gfortran.exe -c fun1.f
$ wine gfortran -shared -o fun1.dll fun1.o -Wl,--out-implib,libfun1_dll.a
$ mcs HelloWorld.cs -r:fun1.dll
error CS0009: Metadata file
`/home/robert/.wine/drive_c/MinGW/bin/fun1.dll' does not contain valid
Compilation failed: 1 error(s), 0 warnings

fun1.f is a trivial function. HelloWorld.cs doesn't actually contain
any reference to fun1; linking with fun1.dll should be a no-op. I
searched for the "does not contain valid metadata" error but wasn't
able to figure out what it means.

If anyone has any advice on where to go from here, I would be very
glad to hear it. Thanks for your time, I appreciate it.

Robert Dodier

PS. Here is fun1.f:
      function fun1(x)
      fun1 = x + 1.0

PPS. Here is HelloWorld.cs:
public class HelloWorld
    static public void Main ()
        Console.WriteLine ("Hello Mono World");

More information about the Mono-list mailing list