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

Interoperability with JAVA using JNA

miguel_campo
Beginner
1,196 Views
I would like to share that I am connecting Java with Fortran DLL and this works just only with Intel compiler in MAC but it does not work with Windows compiler. I have no idea why.
With other compilers like g95 and gfortran works well, so I would like to push Intel Fortran Developer to debug this.
FUNCTION mult(a, b) BIND(C, name='foomult')
    INTEGER,VALUE :: a,b
    INTEGER :: mult

    mult = a * b
END FUNCTIO
When you call foomult from java you receive next error:

Error looking up function 'foomult': The specified procedure could not be found.

This only happend on windows with Intel compiler.
Thanks,
Miguel
0 Kudos
6 Replies
Steven_L_Intel1
Employee
1,196 Views
Probably because the C compiler convention of an underscore prefix is used, so the global name is _foomult, just as it would be if you wrote the same funcion in C. I also don't see an ATTRIBUTES DLLEXPORT directive there - without that no names are exported to the DLL. (This is something Windows requires.)

Unfortunately, Intel Fortran won't let you have both BIND(C) and ATTRIBUTES ALIAS - the latter would be needed to get rid of the underscore. You will probably have to remove the BIND(C) and then add:

!DEC$ ATTRIBUTES DLLEXPORT,ALIAS:"foomult" :: mult
0 Kudos
miguel_campo
Beginner
1,196 Views
I again, and thank you for your quick answer.
I changed to undersocer prefix and it did not work. In addition I have removed BIND(C) and I used !DEC$ ATTRIBUTES DLLEXPORT,ALIAS:"foomult" :: mult but the problem remain in the same way.
When I call it from java the same message apeears:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'foomult': The specified procedure could not be found.

It is strange that just only happen in window, because in mac works and with other gnu compiler works too.

I have no idea why.

Thanks again,

Miguel

0 Kudos
Steven_L_Intel1
Employee
1,196 Views
Can you attach your DLL as a file here? See my signature for how to attach.
0 Kudos
miguel_campo
Beginner
1,196 Views
Of course,
I attach the dll as a result of next code:

FUNCTION mult(a, b) BIND(C, name='foomult')

INTEGER,VALUE :: a,b

INTEGER :: mult

mult = a * b

END FUNCTION

Thanks again,

Miguel

0 Kudos
Steven_L_Intel1
Employee
1,196 Views
As I explained above, if you don't use the !DEC$ ATTRIBUTES directive with the DLLEXPORT clause, no routines will be visible in the DLL. You must add the directive and remove the BIND clause to make it work on Windows.

The DLL you attached did not export any names. This is a difference between Windows and Linux.
0 Kudos
miguel_campo
Beginner
1,196 Views
I am sorry. Now with the

!DEC$ ATTRIBUTES DLLEXPORT,ALIAS:"foomult" :: mult

works well and I can see foomult in java
Thanks so much,
Miguel
0 Kudos
Reply