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

IFX Fortran issue with allocatable string (call of Fortran dll from Java)

jenny_p
Beginner
547 Views

Hello everybody,

first time I address an issue I face in a forum. So, hopefully I have put together everything you need to better understand my problem.

Currently we are calling Fortran dlls from Java using FFI (in our case accordingly to the Panama Project).

 

Our Fortran test routine is very simple. With both IFORT and IFX this is working perfectly fine. The dll is compiling and Java can call the function.

subroutine get_greeting(out_string) bind(C, name = "get_greeting")
      !DEC$ ATTRIBUTES DLLEXPORT:: get_greeting
      implicit none
        character(kind = c_char, len = 1), dimension(*) :: out_string

        character(kind = c_char, len = 30) :: buffer_for_out
        integer :: i

        buffer_for_out = "Hello from Fortran"
        do i = 1, len_trim(buffer_for_out)
          out_string(i) = buffer_for_out(i:i)
        end do
    end subroutine get_greeting

 

Now I add one new line to my code with an allocatable like below to my Fortran program, the dll can be built with IFORT and IFX. So that is fine, too. 

 

subroutine get_greeting(out_string) bind(C, name = "get_greeting")
      !DEC$ ATTRIBUTES DLLEXPORT:: get_greeting
      implicit none
        character(kind = c_char, len = 1), dimension(*) :: out_string

        character(kind = c_char, len = :), allocatable :: buffer2
        character(kind = c_char, len = 30) :: buffer_for_out
        integer :: i

        buffer_for_out = "Hello from Fortran"
        do i = 1, len_trim(buffer_for_out)
          out_string(i) = buffer_for_out(i:i)
        end do
    end subroutine get_greeting

 

BUT now:  when built with IFORT Java can call the dll as before and when built with IFX we are running into the issue 

java.lang.IllegalArgumentException: Cannot open library: ....

 

So that was very weird for us. We have no idea why this one line now causes such an issue by only changing between the two compilers?

Any help would be much appreciated.

 

Labels (1)
0 Kudos
1 Solution
Arjen_Markus
Honored Contributor II
535 Views

It seems likely to me that by the introduction of an allocatable your DLL now depends on an extra runtime library. If that is not in the path, then the program that tries to load your DLL (or shared object) cannot succeed. Use a tool like ldd on Linux or dependency walker on Windows to find out which dynamic libraries are needed.

View solution in original post

1 Reply
Arjen_Markus
Honored Contributor II
536 Views

It seems likely to me that by the introduction of an allocatable your DLL now depends on an extra runtime library. If that is not in the path, then the program that tries to load your DLL (or shared object) cannot succeed. Use a tool like ldd on Linux or dependency walker on Windows to find out which dynamic libraries are needed.

Reply