调用 C++来自 Java 的代码 (GCJ)

发布于 2024-09-04 17:23:54 字数 88 浏览 2 评论 0原文

我正在尝试使用 GCJ 使用 CNI 从 Java 调用 C++,到目前为止我能够从 C++ 调用 Java 代码。如何使用 CNI 从 Java 调用 C++?

I'm trying to invoke C++ from Java using GCJ using the CNI, so far I'm able to invoke Java code from C++. How can I invoke C++ from Java using the CNI?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

他夏了夏天 2024-09-11 17:23:54

我将在 pcent 的答案上进行一些扩展,以阅读 GCJ/CNI 文档

我认为关键是理解整个“CNI C++ 类”概念。

  • 该页面中解释了 CNI C++ 类的创建。
  • 您可以从 CNI C++ 类调用 Java 代码(前提是您已生成头文件) - 这就是您已经执行的操作(从 C++ 调用 Java)。
  • 关键点是可以从 Java 调用 CNI C++ 方法(因为这些类有一组限制以使其与 Java 兼容)。由于 CNI 类只是一个(特定类型的)C++ 类,因此您也可以将其链接到其他库,就像链接任何 C++ 类一样。

大多数 文档 描述了 Java 约定如何在 CNI C++ 中转换班级。

I'll extend somewhat on pcent's answer to read the GCJ/CNI Docs.

I believe that the key is to understand the whole "CNI C++ class" concept.

  • The creation of a CNI C++ class is explained in that page.
  • You can call Java code from a CNI C++ class (provided you have generated header files) - that's what you already do (calling Java from C++).
  • The key point is that CNI C++ methods can be invoked from Java (because these classes have a set of restrictions upon them to make them Java-compatible). And because the CNI class is only a (particular kind of) C++ class, you can also link it to other libraries just as you would link any C++ class.

Most of the documentation describes how the Java conventions translate in a CNI C++ class.

看海 2024-09-11 17:23:54

尝试阅读 GCJ/CNI 文档

Try reading GCJ/CNI Docs

流云如水 2024-09-11 17:23:54

我不是一个优秀的 Java 程序员,但我熟悉 C#/C++ 互操作。对我来说,从本机 C++ 调用托管 C# 的最佳解决方案是使用回调。我认为这也适用于 JNI

尝试阅读:http://www.tidytutorials.com/2009/07/java-native-interface-jni-example-using.html

I'm not a good Java-programmer, but I'm familar with C#/C++ interop. The best solution for me to call from native C++ to managed C# was using Callbacks. I think this applies also to JNI

Try reading: http://www.tidytutorials.com/2009/07/java-native-interface-jni-example-using.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文