-->

bazel for jni: jni.h file not found

2019-07-31 05:07发布

问题:

I'm trying to use bazel to build my JNI library (written in C). No luck after about 4 hours: "jni.h file not found". How can I put the JDK include directories on the search path? Tried using absolute paths but bazel rejects those. Trying to use a new_local_repository for the JDK but cannot see how to make it work.

This is bazel 0.5.3 on MacOS 10.12.6, Java 1.8

回答1:

Can you depend on @local_jdk//:jni_header or some other magic labels from https://github.com/bazelbuild/bazel/blob/117da7a947b4f497dffd6859b9769d7c8765443d/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE? However if you're using custom --java_base it won't work.

E.g. this works for me:

cc_library(
    name = "foo",
    srcs = [ 
        "@local_jdk//:jni_header",
        "@local_jdk//:jni_md_header-linux",
        "foo.cc"
    ],
    includes = [ "external/local_jdk/include/linux" ],
)