3 messages in net.java.dev.jna.users[jna-users] Re: jna and fortran
FromSent OnAttachments
Timothy WallOct 23, 2008 6:46 am 
Timothy WallOct 23, 2008 10:23 am 
Timothy WallNov 3, 2008 12:49 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:[jna-users] Re: jna and fortranActions...
From:Timothy Wall (twal@dev.java.net)
Date:Oct 23, 2008 10:23:56 am
List:net.java.dev.jna.users

On Oct 23, 2008, at 12:58 PM, Kolonay, Raymond M Civ USAF AFMC AFRL/ RBSD wrote:

Hi Tim, Thanks for the quick response. You were correct about the naming convention. The fortran function was showing up with an underscore after the name in the .so file. Once I added this to the java code I was able to directly call the fortran function from java. Next I tried to pass arguments. I was not able to pass int or float or double as a single argument. I think this is because fortran passes these by reference and java by value. However, I was successful at passing int[], float[] and double[] directly from java to fortran. Apparently java passes these by reference.

Technically you're passing the address of the start of the array. There are some XXXByReference classes in the com.sun.jna.ptr package that abstract "type by reference" arguments, but primitive arrays of size one work as well, as you've figured out.

Any suggestions on how to deal with passing the single argument? Or must I always use an array length 1?

Check the gfortran/gcc docs on fortran linkage versus C linkage and find out what "magic", if any, is done differently when linking a fortran share library versus C.

Finally, I am about to try and pass strings and string[]. I'll let you know how that goes.

There is built in support for arguments of type String[] and Pointer[], so you shouldn't have any problem there. As for more complex types, you're treading new ground.

Thanks again for your help.

Regards Ray Kolonay

Raymond M. Kolonay Ph.D. Principal Aerospace Engineer AFRL/RBSD 2130 8th Street Suite 1 Bldg 146, Room 218 WPAFB, OH 45433 Phone: (937) 255-6686 fax: (937) 656-6321 email: Raym@wpafb.af.mil

-----Original Message----- From: Timothy Wall [mailto:twal@dev.java.net] Sent: Thursday, October 23, 2008 9:47 AM To: Kolonay, Raymond M Civ USAF AFMC AFRL/RBSD Cc: Michael Sobolewski; Strong, Daniel D Civ USAF AFMC AFRL/RBSD; use@jna.dev.java.net Subject: Re: jna and fortran

What is the output of "nm" against the shared library? That will indicate what the available function names are and whether they're somehow mangled.

I'm not familiar with gfortran shared library output, but assuming the shared library presents a C calling convention (i.e. doesn't need extra linker/compiler magic to allow the C code to call it) then JNA should be able to call it as well.

First try a simple function with no arguments. That'll get the linkage/naming issues out of the way.

On Oct 23, 2008, at 8:42 AM, Kolonay, Raymond M Civ USAF AFMC AFRL/ RBSD wrote:

Dear Mr. Wall, I was given you name by Dr. Mike Sobolewski from Texas Tech University. He thought you may be able to answer my questions concerning the use of JNA and FORTRAN. I have been successful in creating a c shared object and calling it from java using jna. But when I try and create a fortran shared object and call it from java I get an "UnsatisfiedLinkError: Error looking up function" at run time when I try and call the function. I was able to take that fortran shared object, declare it external in a c routine and then call the c shared object from java which in turn call the fortran shared object. But I would really like to be able to go directly from java to fortran. Is this possible? I'm running on a linux 64 bit machine the kernel version is 2.6.18-33.el5. I have four processors - all x86_64. I'm running Red Hat linux 4.1.2-14. The versions of the compilers I'm using are gcc version 4.1.2, gfortran version 4.1.2. The compiler and link flags that I'm using are gcc -c -fPIC gfortran -c -fPIC to create the shared library I'm using the command gcc -shared *.o -o libavus_kriging.so

Any help in this matter would be greatly appreciated.

Regards Ray Kolonay Raymond M. Kolonay Ph.D. Principal Aerospace Engineer AFRL/RBSD 2130 8th Street Suite 1 Bldg 146, Room 218 WPAFB, OH 45433 Phone: (937) 255-6686 fax: (937) 656-6321 email: Raym@wpafb.af.mil