0

I know that it is possible to generate the JNI given a Java implementation using javac but is there a way to do the opposite (a "cjava")?

So if I have something like this:

mypackage/mylib.h:

void helloWorld();

mypackage/mylib.c:

#include <iostream>

void helloWorld() {
    std::cout << "Hello World!" << std::endl;
}

Shouldn't it be possible to generate the JNI like

mylib-jni.c:

#include "mypackage/mylib."

JNIEXPORT jlong JNICALL Java_mypackage_helloWorld() {
    helloWorld();
}

and

Mylib.java:

package mypackage;

public class Mylib {    
    public native void helloWorld();    
}

etc.

Somehow I am not stumbling upon something like that.

Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
  • Have you looked at [JNA](https://github.com/java-native-access/jna/blob/master/www/GettingStarted.md) (and the related [JNAerator](https://github.com/nativelibs4java/JNAerator)) or [SWIG](http://www.swig.org/)? – Botje Aug 02 '19 at 11:42

1 Answers1

0

Try antlr. It has a grammar file for C++ and gives you full control.

For the generation of java you could use the cgV19 i hust released. My picture is:

parse the C++ file with antlr and build a model loader for cgV19 with it. cgV19 uses this C++ parser to load a model give cgV19 a cartridge that can generate your java files from that model