简体   繁体   English

使用JNI从Java调用fortran dll

[英]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. 我在Fortran中有一个Fifp.dll,其中包含一个简单的void RESET()函数,并尝试从我的Java代码中调用它。 I made a simple java test class: 我做了一个简单的java测试类:

public class TestJni {

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

public native void RESET();
}

I made a .h file from it, and compiled it. 我从中制作了一个.h文件,并对其进行了编译。 I also made a bridge file myBridge.c: 我还制作了一个桥文件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: 这是我在Visual Studio x64命令提示符下尝试的命令:

> 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) 并且还带有-FeFifp.dll选项,它给了我相同的错误: LNK2019:无法解析的外部符号RESET(和main)

So what am I doing wrong ? 那么我在做什么错呢?
Is there an option to specify the external dll to include ? 是否可以指定要包含的外部dll?
Am I in the right way to perform the new TestJni().RESET() call ? 我是否以正确的方式执行new TestJni().RESET()调用?

Any help appreciated... 任何帮助表示赞赏...

  1. Prepare a Fifp.DEF file for the prebuilt Fortran DLL. 为预构建的Fortran DLL准备一个Fifp.DEF文件。

     LIBRARY Fifp.dll EXPORTS RESET 
  2. Create the LIB from DEF. 从DEF创建LIB。

     lib /def:Fifp.DEF /OUT:Fifp.lib 
  3. Build the FifpBridge.dll from myBridge.c and Fifp.LIB. 从myBridge.c和Fifp.LIB构建FifpBridge.dll。

     cl /LD myBridge.c /link Fifp.LIB 
  4. Change the Java statement to loadLibrary("FifpBridge"). 将Java语句更改为loadLibrary(“ FifpBridge”)。 The bridge will load the Fortran DLL without your intervention. 该桥将在无需您干预的情况下加载Fortran DLL。

  5. Make sure both FifpBridge.dll and Fifp.dll are available at run time. 确保FifpBridge.dll和Fifp.dll在运行时都可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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