LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-31-2004, 02:44 AM   #1
stiphon
LQ Newbie
 
Registered: May 2004
Location: Beijing, China
Posts: 4

Rep: Reputation: 0
Angry how to get the *.dll or *.so by applying JNI under the java, c++ and fortran


In my programme, java, c++ and fortran play different effect. The java language is used for operation interface, such as the menus, buttons,frames. And the c++ and fortran language are used for the special implement, for example, the fortran can result in the data for model. The fortran section is called by c++ with "extern "C" ".

The following sentence is that the fortran is called by c++


extern "C" {

void gear_(int *N, double *T0, double *H0, double *Y0, double *TOUT, double *EPS,
int *MF, int *INDEX, double *YINIT, double *Y, int *N0);
}


the gear function written by fortran.


SUBROUTINE GEAR(N,T0,H0,Y0,TOUT,EPS,MF,INDEX,YINIT,Y,N0)
IMPLICIT REAL*8 (A-H,O-Z)
INTEGER ISTRT
REAL*8 T0,H0,Y0,TOUT,EPS,CM
REAL*8 T,H,HMIN,HMAX,EPSC,UROUND,YMAX,ERROR,SAVE1,SAVE2,
* PW,EPSJ,HUSED
REAL*8 Y,TOUTP,AYI,D
COMMON /PRINT/ ICHAR
........

Many years ago, the model was gotten by the used the c++ and fortran. But now, considering the different operation system, the java is adapted . My question is how to get the *.dll or *.so by applying JNI under the complex enviroment with java, c++, fortran. Any suggestion is thanks.

Last edited by stiphon; 05-31-2004 at 02:47 AM.
 
Old 06-04-2004, 04:10 AM   #2
postmaik
Member
 
Registered: May 2004
Location: @ Lake Constance, Germany
Distribution: FC3, Kernel 2.6.10
Posts: 46

Rep: Reputation: 15
just want to give some experience from other projects...

Hey to Bejing,

it looks not that easy, but hopefully I can give you at least some experience. I did those things with only Java and C using the Native Interface between them. Now I'd like to explain you how I did my stuff... (this is the usual way to handle things with the JNI)
First I had the Java code and declared the methods I needed to implement in C. The methods were marked as static native. This has to be done to tell the Native Interface where to find the reference to C. After declaring the methods you can Java let create the needed header file:
javah -jni <class>
This will create a *.h file which includes all the prototypes of the native methods. It will name the methods like you have to implement them. The JNI can only find the native methods in the DLL if they're named as found in the header. (The name represents the package structure of your Java code.)
The next step after implementing the C source is to create (compile and link and so on) the DLL, which then has to be included in the Java code that wants to use the native code. This can be done by
System.loadLibrary( <name_of_dll_as_String>) or
System.load( <name_of_dll_as_String>)
The first method tries to load the library from the system path (under windows would be windows/system32), the second can load a library directly by passing the whole directory structure and library name as String (e.g. /home/postmaik/something.so).
Don't forget to put the System.loadLibrary() or System.load() into a static block so that the DLL will be loaded when creating the Java object.

So, now I think you should try or find out whether there is an analogous procedure with using Fortran code with the JNI or if it is possible at all...

I wish you all the best!

Cheers,
Maik

P.S.: Please post if there are any questions to what I wrote...
 
Old 06-04-2004, 04:26 AM   #3
stiphon
LQ Newbie
 
Registered: May 2004
Location: Beijing, China
Posts: 4

Original Poster
Rep: Reputation: 0
thank to Berlin

i have known how to use the C in the java codes with JNI.
Yes, you guess right. i are trying to find out whether there is an analogous procedure with using Fortran code now.
 
Old 06-04-2004, 05:32 AM   #4
postmaik
Member
 
Registered: May 2004
Location: @ Lake Constance, Germany
Distribution: FC3, Kernel 2.6.10
Posts: 46

Rep: Reputation: 15
Hi again,

is that something that can help you?
http://userweb.elec.gla.ac.uk/i/iainw/jni/

Maik
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JAVA JNI program to access shared library sabliny Programming 3 11-17-2005 05:13 PM
does linux fortran compiler in fedora 4 support VAX FORTRAN? terrence Programming 17 08-31-2005 08:59 AM
print problem with Java and C JNI trutnev Programming 0 06-20-2005 11:28 AM
Regarding interfacing of C with JAVA thru JNI nedian123 Programming 3 07-28-2004 02:39 PM
core dump while executing a c function from java using JNI kaustubh Linux - Newbie 0 05-25-2002 02:11 AM


All times are GMT -5. The time now is 08:06 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration