简体   繁体   English

从Java调用C ++代码(GCJ)

[英]Invoking C++ code from Java (GCJ)

I'm trying to invoke C++ from Java using GCJ using the CNI, so far I'm able to invoke Java code from C++. 我正在尝试使用CNI使用GCJ从Java调用C ++,到目前为止我能够从C ++调用Java代码。 How can I invoke C++ from Java using the CNI? 如何使用CNI从Java调用C ++?

I'll extend somewhat on pcent's answer to read the GCJ/CNI Docs . 我会稍微谈谈pcent读取GCJ / CNI Docs的答案。

I believe that the key is to understand the whole "CNI C++ class" concept. 我认为关键是要了解整个“CNI C ++类”的概念。

  • The creation of a CNI C++ class is explained in that page . 页面解释了CNI C ++类的创建。
  • 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++). 您可以从CNI C ++类调用Java代码(假设您已经生成了头文件) - 这就是您已经做过的事情(从C ++调用Java)。
  • 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). 关键是可以从Java调用CNI C ++方法 (因为这些类对它们有一组限制,使它们与Java兼容)。 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. 并且因为CNI类只是一种(特定类型的)C ++类,所以您也可以将它链接到其他库,就像链接任何C ++类一样。

Most of the documentation describes how the Java conventions translate in a CNI C++ class. 大多数文档描述了Java约定如何在CNI C ++类中进行转换。

尝试阅读GCJ / CNI文档

I'm not a good Java-programmer, but I'm familar with C#/C++ interop. 我不是一个优秀的Java程序员,但我熟悉C#/ C ++互操作。 The best solution for me to call from native C++ to managed C# was using Callbacks . 我从本机C ++调用托管C#的最佳解决方案是使用Callbacks I think this applies also to JNI 我认为这也适用于JNI

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

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

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