Sign in to follow this  
smiley_horse

[java] Is it possible to call c++ from java with CNI?.

Recommended Posts

Looking att gcj manual (about cni section): there is not a word how to call c++ code from java program. Not a singel word or example in whole section. I have also googled pretty much around and there are several ppl offering some basic tutorials and mentioning CNI, but seems like anyone on earth suddenly want to call java from their c++ code. Also is it possible to go other way around, or I have to use JNI even when compiling with gcj? I just need some simple pointer so I can start use CNI ... if anyone has some plz handle it over.

Share this post


Link to post
Share on other sites
GCJ is used to build native interfaces for Java. Once that is done, you just import the appropriate class file and use it like you would any other java class.

Share this post


Link to post
Share on other sites
GCJ is used to build native interfaces for Java. Once that is done, you just import the appropriate class file and use it like you would any other java class.

Oki ... can u tell me how? That's what I'm asking.

Just a simple quetion: have u ever called c++ method from your java prog with CNI?

[Edited by - smiley_horse on July 8, 2005 6:13:05 PM]

Share this post


Link to post
Share on other sites
I guess so.
________________________________________________________
However I have figured it out. I found this project and took some peek into code & makefiles: http://www.ii.uib.no/~rolfwr/jcnix, which was of help.

If anyone else is wondering, the process is:

1. create java class
2. compile java class with gcjh to produce header file
3. compile java class again with "gcjh -stubs classname" to get .cc file (optional)
4. compile .cc file with gcc as ordinary c++ file (with -c option)
5. compile java class with gcj, pass it .o file from step 4

Actually there is no difference from using jni, but they could have say that :), it could spare some wondering.

[Edited by - smiley_horse on July 9, 2005 10:28:28 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this