简体   繁体   English

从C ++生成JNI Bridge和Java接口

[英]Generate JNI Bridge and Java interfaces from C++

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 ")? 我知道可以使用javac在给定的Java实现下生成JNI,但是有没有办法做相反的事情(“ cjava ”)?

So if I have something like this: 所以,如果我有这样的事情:

mypackage/mylib.h : mypackage/mylib.h

void helloWorld();

mypackage/mylib.c : mypackage/mylib.c

#include <iostream>

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

Shouldn't it be possible to generate the JNI like 是否应该像这样生成JNI

mylib-jni.c : mylib-jni.c

#include "mypackage/mylib."

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

and

Mylib.java : Mylib.java

package mypackage;

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

etc. 等等

Somehow I am not stumbling upon something like that. 我不以某种方式绊脚石。

Try antlr. 尝试antlr。 It has a grammar file for C++ and gives you full control. 它具有C ++的语法文件,可让您完全控制。

For the generation of java you could use the cgV19 i hust released. 对于Java的生成,您可以使用必须发布的cgV19。 My picture is: 我的照片是:

parse the C++ file with antlr and build a model loader for cgV19 with it. 使用antlr解析C ++文件,并使用它为cgV19构建模型加载器。 cgV19 uses this C++ parser to load a model give cgV19 a cartridge that can generate your java files from that model cgV19使用此C ++解析器加载模型,为cgV19提供一个可从该模型生成Java文件的盒式磁带

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM