gpt4 book ai didi

bazel - 多个 Bazel BUILD 文件出错 : "Target ' bar' is not visible from target 'foo' "

转载 作者:行者123 更新时间:2023-12-03 18:32:24 24 4
gpt4 key购买 nike

我的项目如下结构:

$ tree
.
├── bar
│   ├── bar.cpp
│   └── BUILD
├── BUILD
├── foo.cpp
└── WORKSPACE
./BUILD 的内容:
cc_binary(
name = "foo",
srcs = [ "foo.cpp" ],
deps = [ "//bar" ],
)
bar/BUILD 的内容:
cc_library(
name = "bar",
srcs = ["bar.cpp"],
)

如果我构建 foo ,我会收到以下错误:
Target '//bar:bar' is not visible from target '//:foo'. Check the visibility declaration of the former target if you think the dependency is legitimate.

我需要做什么才能解决依赖关系并成功构建 foo

最佳答案

Bazel docs :

However, by default, build rules are private. This means that they can only be referred to by rules in the same BUILD file. [...] You can make a rule visibile to rules in other BUILD files by adding a visibility = level attribute.



在这种情况下, bar/BUILD 应如下所示:
cc_library(
name = "bar",
srcs = ["bar.cpp"],
visibility = ["//__pkg__"],
)

附加行 visibility = ["//__pkg__"] 允许当前 WORKSPACE 中的所有 BUILD 文件访问目标 bar

关于bazel - 多个 Bazel BUILD 文件出错 : "Target ' bar' is not visible from target 'foo' ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36954130/

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