Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Create a Fortran DLL?

PlettB
New Contributor I
223 Views

I have the simplest example I can think of:

 

! minimal_example.f90
function add_numbers(a, b) bind(C, name="add_numbers")
  integer, intent(in) :: a, b
  integer :: add_numbers
  add_numbers = a + b
end function add_numbers

 

I compile this using:

 

ifx.exe -dll -o minimal_example.dll minimal_example.f90

 

I then try:

 

dumpbin /exports minimal_example.dll

 

I get:

 

Microsoft (R) COFF/PE Dumper Version 14.42.34435.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Dump of file minimal_example.dll

File Type: DLL

  Summary

        1000 .data
        1000 .pdata
        1000 .rdata
        1000 .reloc
        1000 .text

 

No sign of "add_numbers".  What gives?

 

P.S. I also tried "ifort" with the same results.

0 Kudos
1 Solution
PlettB
New Contributor I
196 Views

Ugh! I should never have posted this. Just a few more minutes of research and I have it working!

 

In case anyone else looks to this thread for help, this solved my issue:

integer, value, intent(in) :: a, b

View solution in original post

0 Kudos
2 Replies
PlettB
New Contributor I
213 Views

I guess I posted that too quickly!  I found I needed to add:

!DEC$ ATTRIBUTES DLLEXPORT::add_numbers

However, now that I've done that, I'm trying the following P/Invoke declaration:

        [DllImport("minimal_example.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int add_numbers(int a, int b);

And I'm getting:

System.AccessViolationException: Attempted to read or write protected memory.

Any ideas? 

0 Kudos
PlettB
New Contributor I
197 Views

Ugh! I should never have posted this. Just a few more minutes of research and I have it working!

 

In case anyone else looks to this thread for help, this solved my issue:

integer, value, intent(in) :: a, b
0 Kudos
Reply