简体   繁体   中英

Call fortran dll from java using JNI

I have a Fifp.dll in fortran with a simple void RESET() function and try to call it from my Java code. I made a simple java test class:

public class TestJni {

static {
    System.loadLibrary("Fifp");
}

public native void RESET();
}

I made a .h file from it, and compiled it. I also made a bridge file myBridge.c:

#include <stdio.h>
#include "TestJni.h"

extern void RESET();

JNIEXPORT void JNICALL Java_TestJni_RESET(JNIEnv *env, jobject obj) {
    printf("Before DLL call\n");
    RESET();
    printf("After DLL call\n");
}

Now I'm not able to compile it. This is the command I tried in a Visual Studio x64 comand prompt:

> cl -I"C:\path\to\jdk\include\win32" -I"C:\path\to\jdk\include" myBridge.c

and also with a -FeFifp.dll option, it gives me the same error: LNK2019: unresolved external symbol RESET (and main)

So what am I doing wrong ?
Is there an option to specify the external dll to include ?
Am I in the right way to perform the new TestJni().RESET() call ?

Any help appreciated...

  1. Prepare a Fifp.DEF file for the prebuilt Fortran DLL.

     LIBRARY Fifp.dll EXPORTS RESET 
  2. Create the LIB from DEF.

     lib /def:Fifp.DEF /OUT:Fifp.lib 
  3. Build the FifpBridge.dll from myBridge.c and Fifp.LIB.

     cl /LD myBridge.c /link Fifp.LIB 
  4. Change the Java statement to loadLibrary("FifpBridge"). The bridge will load the Fortran DLL without your intervention.

  5. Make sure both FifpBridge.dll and Fifp.dll are available at run time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM