Invoking C++ code from Java (GCJ)
Asked Answered
R

3

8

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?

Roche answered 8/6, 2010 at 12:29 Comment(0)
J
5

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.

Jocund answered 8/6, 2010 at 13:32 Comment(0)
K
1

Try reading GCJ/CNI Docs

Kelwin answered 8/6, 2010 at 12:56 Comment(0)
H
-2

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

Handle answered 8/6, 2010 at 13:32 Comment(1)
The question wasn't about JNI -- it was about CNI, which is a different beast entirely.Antwanantwerp

© 2022 - 2024 — McMap. All rights reserved.