简体   繁体   English

JNI加载库

[英]JNI load library

I am developing an aplication in java to comunicate with a simulator, X-Plane, using the x-plane sdk, it have it in C. I downloaded the SDK and consist in .libm .h and .cpp files. 我正在用Java开发一个应用程序,以便与使用X-plane sdk的模拟器X-Plane进行通讯,并在C中使用它。我下载了SDK,并包含.libm .h和.cpp文件。

I have made a search in the internet to see how to load these libraries in my programs and i found the Java Native Interface, so i start to read about that, looking for examples that matches my cases, but i only found the same case, how to create the c library. 我在互联网上进行了搜索,以了解如何在程序中加载这些库,然后我找到了Java Native Interface,因此我开始阅读有关内容,寻找与我的情况相符的示例,但我只发现了相同的情况,如何创建C库。

My problem is that i already have the header files and the library and is not the .dll. 我的问题是我已经有了头文件和库,而不是.dll。

How can i make the load without crating myself the library 我如何在不创建库的情况下进行负载

I know that problably is a very easy way, but i do not know, and i appreciate very much the effort to answer me. 我知道可能是一个非常简单的方法,但是我不知道,我非常感谢为我回答的努力。

If it's a strict C interface, look at JNA: 如果它是严格的C接口,请查看JNA:

http://en.wikipedia.org/wiki/Java_Native_Access http://en.wikipedia.org/wiki/Java_Native_Access

If you can't recompile the source code into a dynamic library (eg, a .so file) another hack you can do is to make a simple .c wrapper that statically links in the static library and compile that into a dynamic library. 如果您无法将源代码重新编译为动态库(例如.so文件),则可以采取的另一种措施是制作一个简单的.c包装器,将其静态链接到静态库中,然后将其编译为动态库。 The wrapper can "forward" the calls you need into the static library in order to ensure that the things you need from the static library are included in the binary. 包装程序可以将您需要的调用“转发”到静态库中,以确保二进制库中包含您需要的静态库中的内容。

Here is an example of this (where the .o files on that answer's command line would be replaced by your wrapper). 是一个示例(该答案命令行上的.o文件将由包装器替换)。

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

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