简体   繁体   English

没有C ++包装器库的Java本机调用

[英]Java Native Invocation without C++ wrapper lib

is there a way to invoke functions in native libraries (Windows .dll's, Linux .so's), withouth having to write a C++ wrapper dealing with JEnv and "this" pointers? 有没有一种方法可以调用本机库(Windows .dll,Linux .so)中的函数,而不必编写处理JEnv和“ this”指针的C ++包装器?

I'm missing C#-alike functionality in this regard, where one can link with native functions easily without writing bridge libraries, leaving up to the compiler marshaling details. 在这方面,我缺少与C#相似的功能,该功能可以轻松地与本机函数链接,而无需编写桥库,而让编译器编组细节。

Thanks, Emilio. 谢谢,埃米利奥。

You can use Java Native Access, JNA , to do exactly what you want. 您可以使用Java Native Access JNA来做您想做的事情。

Note that the usual wrapper library wouldn't be written in C++, but in C. 请注意,通常的包装库不是用C ++编写的,而是用C语言编写的。

I hated having to write JNI code and looked at JNA but it didn't seemed to be that widely used and might present a potential performance problem. 我讨厌不得不编写JNI代码并查看JNA,但它似乎没有得到广泛使用,并且可能会带来潜在的性能问题。 Use SWIG instead. 请改用SWIG Once you are up and running it doesn't take that long to script it and get it generating your JNI interface code for you. 一旦启动并运行,就不需要花很长时间来编写脚本并让它为您生成JNI接口代码。

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

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