gpt4 book ai didi

java - 如果目标未在工作区根目录声明,则无法找到 jni.h

转载 作者:行者123 更新时间:2023-11-30 06:13:04 26 4
gpt4 key购买 nike

我有一个相对简单的构建文件:

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

使用更简单的源文件:

#include <jni.h>

如果这两个文件都位于工作区根目录下,则一切正常:

$ bazel build //:target
INFO: Analysed target //:target (1 packages loaded).
INFO: Found 1 target...
Target //:target up-to-date:
bazel-bin/libtarget.a
INFO: Elapsed time: 0.348s, Critical Path: 0.00s
INFO: Build completed successfully, 1 total action

但是,如果我将它们嵌套在目录中,构建就会失败:

$ bazel build //nested:target
WARNING: /path/to/workspace/nested/BUILD:3:10: in srcs attribute of cc_library rule //nested:target: please do not import '@local_jdk//:include/jni.h' directly. You should either move the file to this package or depend on an appropriate rule there
WARNING: /path/to/workspace/nested/BUILD:3:10: in srcs attribute of cc_library rule //nested:target: please do not import '@local_jdk//:include/linux/jni_md.h' directly. You should either move the file to this package or depend on an appropriate rule there
INFO: Analysed target //nested:target (0 packages loaded).
INFO: Found 1 target...
ERROR: /path/to/workspace/nested/BUILD:1:1: C++ compilation of rule '//nested:target' failed (Exit 1)
nested/hello.cc:1:10: fatal error: jni.h: No such file or directory
#include <jni.h>
^~~~~~~
compilation terminated.
Target //nested:target failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.424s, Critical Path: 0.09s
FAILED: Build did NOT complete successfully

我是不是理解错了?

$ bazel version
Build label: 0.12.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Aug 4 01:22:27 +50246 (1523462001747)
Build timestamp: 1523462001747
Build timestamp as int: 1523462001747

最佳答案

不是修复,而是解决方法...

在顶级 BUILD 文件中:

cc_library(
name = "jni_headers",
srcs = [
"@local_jdk//:jni_header",
"@local_jdk//:jni_md_header-linux",
],
includes = [
"external/local_jdk/include",
"external/local_jdk/include/linux",
],
visibility = [
"//visibility:public",
],
)

在嵌套目录中:

cc_library(
name = "target",
srcs = [
"hello.cc",
],
deps = [
"//:jni_headers",
]
linkstatic = 1
)

关于java - 如果目标未在工作区根目录声明,则无法找到 jni.h,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49824574/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com