简体   繁体   English

用 Java 包装 C++ 模块

[英]Wrapping C++ modules in Java

I've inherited a project, originally written in C++ .我继承了一个最初用C++编写的项目。 Due to implementation requirements, I need to either re-write the project in a JVM based language, like Java or Kotlin , or simply wrap the existing code in a Java or Kotlin (RESTful) API.由于实现要求,我需要使用基于 JVM 的语言(如JavaKotlin重新编写项目,或者简单地将现有代码包装在JavaKotlin (RESTful) API 中。

The existing code base is also entangled with an very old network simulation framework.现有的代码库还纠缠着一个非常古老的网络模拟框架。 I'm therefore leaning heavily towards untangling the simulation framework and wrapping the C++ code using something like JNI and SWIG to implement in a non simulated environment.因此,我非常倾向于解开模拟框架并使用JNISWIG 之类的东西包装C++代码以在非模拟环境中实现。

I'm wondering if JNI and SWIG are still the best options available?我想知道JNISWIG是否仍然是最好的选择?

Any advice will be greatly appreciated!任何建议将不胜感激!

Wrapping with JNI (or SWIG) requires a clever definition of the API.使用 JNI(或 SWIG)包装需要对 API 进行巧妙的定义。 See a nice explanation here .在这里看到一个很好的解释。 There exist some C++ frameworks that make JNI operations easier on the C++ side, consider them early, before you get too deeply invested in reference management.有一些 C++ 框架可以使 C++ 方面的 JNI 操作更容易,在您对引用管理进行过多投资之前,尽早考虑它们。 From what you write, it may be necessary also to provide some Java interface below the C++ layer, eg we use the the Java network APIs on Android, even from C++ code.从您编写的内容来看,可能还需要在 C++ 层下方提供一些 Java 接口,例如,我们在 Android 上使用 Java 网络 API,甚至来自 C++ 代码。

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

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