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

Started by
4 comments, last by smiley_horse 18 years, 9 months ago
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.
Advertisement
Look up NoodleGlue.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Thnks for fast anser - interesting; but it's kind-a tool for generating JNI code.

However I am looking for info about calling c++ code with CNI, if it's possible.
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.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

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]
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]

This topic is closed to new replies.

Advertisement