【问题标题】:"undeclared inclusion(s)" in bazel with headers in subdirectoriesbazel中的“未声明的包含”,子目录中有标题
【发布时间】:2018-01-10 15:13:46
【问题描述】:

我正在尝试在 C++ bazel 项目中使用 ArduinoJson。它是一个只有头文件的库,头文件位于 src 下的子目录中。但我收到一个未声明的包含错误。

这是//Third-Party/ArduinoJsoncc_library def 的样子:

cc_library(
    name = "ArduinoJson",
    hdrs = glob(["5.12.0/src/**"]),
    includes = [
        "5.12.0/src",
        "5.12.0/src/ArduinoJson",
    ],
    visibility = ["//visibility:public"],
)

使用它的目标(序列化)确实在它的deps 中有//Third-Party/ArduinoJson

这是错误:

ERROR: /[...]/Serialization/BUILD:1:1: undeclared inclusion(s) in rule '//[...]/Serialization:Serialization':
this rule is missing dependency declarations for the following files included by '[...]/Serialization/JsonDeserializer.cpp':
  '[...]/Third-Party/ArduinoJson/5.12.0/src/ArduinoJson/Data/Encoding.hpp'
  '[...]/Third-Party/ArduinoJson/5.12.0/src/ArduinoJson/Serialization/FloatParts.hpp'
  '[...]/Third-Party/ArduinoJson/5.12.0/src/ArduinoJson/Polyfills/math.hpp'
  '[...]/Third-Party/ArduinoJson/5.12.0/src/ArduinoJson/TypeTraits/FloatTraits.hpp'
Target //[...]/Serialization:Serialization failed to build

因为它只抱怨src 子目录中的文件,例如src/Data/Encoding.hpp,我猜这可能与它有关?

这不是 "How to resolve bazel “undeclared inclusion(s)” error?" 的重复,因为它是通过执行我已经对 deps 执行的操作来解决的。

【问题讨论】:

  • 使用Third-Party/ArduinoJson/5.12.0/scripts/build-single-header.sh 脚本,可以解决这个问题。虽然这不是一个真正的解决方案,但保持问题开放。
  • 我创建了一个很小的重现工作区,但无法重现您观察到的内容。你用什么编译器?你如何包含那些受影响的标题(“” vs )?您能否设置一个演示该问题的小型复制器?如果您认为这是一个错误,甚至可以为此打开一个 github 问题。

标签: bazel


【解决方案1】:

确保Third-Party/ArduinoJson 的子目录中没有BUILD 文件,否则Bazel 会将这些文件视为包,glob 不会从中获取文件。

如果您在这些子目录中确实有 BUILD 文件,则需要在其中创建 cc_library 规则,在 //Third-Party/ArduinoJson:ArduinoJson 中导出您想要的标头,并依赖 ArduinoJson 中的这些 cc_libraries。

【讨论】:

  • 不,那里没有 BUILD 文件。
猜你喜欢
  • 1970-01-01
  • 2022-06-13
  • 1970-01-01
  • 2018-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-03
  • 1970-01-01
相关资源
最近更新 更多