英文:
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
- Understand the C code
- Write a JNI wrapper for C code
- 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论