Bazel:如何构建使用JNI的C ++应用程序?

时间:2019-05-31 08:14:00

标签: java java-native-interface bazel

this answer中,@ hlopko显示了如何构建调用本机代码的Java应用程序。但是,我如何构建一个调用Java代码的本机应用程序?

我的尝试(以下详述)失败了:

Error occurred during initialization of VM
Unable to load native library: 

他是代码。 BUILD.bazel

cc_binary(
    name = "main",
    srcs = [
        "main.cc",
        "@local_jdk//:jni_header",
        "@local_jdk//:jni_md_header-linux",
        "@bazel_tools//tools/jdk:current_java_runtime",
    ],
    includes = [ "external/local_jdk/include", 
    "external/local_jdk/include/linux"],
)

main.cc

#include <jni.h>

int main() {
  JNIEnv *env;
  JavaVM *jvm;
  JavaVMInitArgs vm_args;
  JavaVMOption options[0];
  jint res;

  vm_args.version = JNI_VERSION_1_4;
  vm_args.options = options;
  vm_args.nOptions = 0;
  vm_args.ignoreUnrecognized = JNI_FALSE;

  /* Create the Java VM */
  res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
}

0 个答案:

没有答案