Silverfrost Forums

Welcome to our forums

Java-C-Fortran interoperability

9 Aug 2006 3:29 #911

Hi, I have developed a Fortran dll, created with FTN95 for .Net 2003. I call this dll from unmaneged Visual C++ code (exe) and I have no problems with both implicit (load time dynamic linking) and explicit (runtime) linking. The problems arose when a tried to call the above C++ code (but compiled as dll) from Java using the Java Native Interface and thus to have Java->C->Fortran interoperability. There are no compile or link errors, but I receive the following run-time error: javaw.exe -Application error

 The instruction at '0x424a5c64' referenced memory at '0x00000000'. The memory could not be 'written'.

There is no error if I don't call the Fortran dll at all - I mean the Java-C part works. Have you any suggestions about the problem?

My second question is : I saw in FTN95 VisualCInteroperability example that __cdecl calling convention is assumed. How can I use __stdcall when caling Fortran functions from C++? I couldnt find anything about this in the documentation.

Best regards

9 Aug 2006 11:15 #913

In answer to your second question, you can put F_STDCALL before SUBROUTINE and FUNCTION in your Fortran code.

An alternative, if you are using FTN95 version 4.91, is to put /F_STDCALL on the FTN95 command line but this is a new feature and so it is not fully tested.

11 Aug 2006 11:32 #918

Thanks for the answer. I've tried to put F_STDCALL before the SUBROUTINE and it worked. I still can't resolve my first question. I think that JVM has problem with loading my Fortran dll which is called by my cpp wrapper dll (both Win 32). I've tried to do some debugging (Visual Studio) and I only saw that the Fortran library salflibc.dll was loaded at a relocated base address and was marked with red exclamation point. Have I to link my Fortran dll with salflibc.lib, or this is done automaticaly? Regards

11 Aug 2006 12:59 #919

When you are creating the Fortran DLL, the linker finds salflibc.dll for you. At runtime, salflibc.dll must be 'visible' to the Fortran DLL. You could try puting a copy of both the Fortran DLL and salflibc.dll in the same folder as the executable.

11 Aug 2006 1:52 #920

I have already put the dlls in the same folder as the executable, but there was no difference. And what about Java - have you ever tried to call FTN dll from Java code through C wrapper dll? I ask this because I am trying to understand where is the problem - in me, in some Java - FTN incompatibility, or elsewhere in something having memory/pointer bugs.

11 Aug 2006 11:58 #922

Sorry. I have not used Java in this way.

Please login to reply.