为现有的 C 库编写 JNI。

huangapple go评论56阅读模式
英文:

Writing JNI for an existing C Library

问题

以下是我的情境:

我必须开发一个需要与 C 库(DNP3 库)通信的 Java 代码,我假设以下是步骤:
1)理解 C 代码
2)为 C 代码编写 JNI 包装器
3)编写一个调用 JNI 的 Java 程序,JNI 再调用 C 代码

我从未使用过 JNI,在查阅了一些示例后,我发现它们通常先编写 Java 代码,然后生成一个 .h 文件(JNI),然后再生成一个相应的 C 文件。

你能否为我提供一篇与这种方式相反的文章,即 C 库(.c)-> JNI -> Java 代码?

提前感谢你,Rakesh

英文:

Below is my scenario

I have to develop a java code that needs to communicate with C Library ( DNP3 Library ) , i assume below are the steps

  1. Understand the C code
  2. Write a JNI wrapper for C code
  3. Wite a Java program to call the JNI which in turn calls the C code

I have never worked on JNI , going through few examples i found they write the java code first and generate a .h file (JNI ) and then a corresponding C file.

Can you please reference me to any article that goes the other way round like C library (.c) -> JNI -> Java code ?

Thanks in advance
Rakesh

答案1

得分: 1

看看 SWIG,它提供了对你的 C 库的低级 Java 抽象,然后在其上构建一个更高级别的 Java 库。在创建语言绑定时,这是一种常见的方法。

英文:

Look at SWIG for a low level Java abstraction of your C library, then build a higher level Java library on top of that. This is a common approach when creating language bindings.

huangapple
  • 本文由 发表于 2020年9月10日 19:24:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/63828670.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定