Boost logo

Boost Users :

Subject: Re: [Boost-users] Possible to use with JNI?
From: Alain Leblanc (aalebl_at_[hidden])
Date: 2015-04-15 11:04:03


2015-04-15 10:29 GMT-04:00 Lorenzo Trivelli <trivelli.lorenzo_at_[hidden]
>:

> At 06:30 13/04/2015, you wrote:
> >Hi, I really need to use Java with this library. Is it possible to use
> JNI on this library or do I need to convert this library to Java? I find
> the latter task is going to be really difficult so I hope that I can use
> JNI.
> >
> >Thank you for your help.
>
> Hi, AFAIK it is not easy to do that due to C++ name mangling and
> the absence of any ABI in C++ itself like C
>
> A possible but limited workaround should be to create a DLL with a C
> interface
> which uses the boost objects you need. Next, you can call it through JNI,
> but obviously you can pass only basic data types
>
> regardds
> Lorenzo
>
>
>
As Lorenzo indicated you need to create a C++ layer between your java code
and the boost libraries. You won't be able to call the boost functions
directly from your java code. Your C++ jni code can actually read instance
variables from a java object (see for instance the JNI function
GetDoubleField). But you will be spending a lot of time writing C++ code to
create C++ objects from java object, and then to create Java objects from
C++ when you return the results from executing the boost code.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net