How to resolve bazel “undeclared inclusion(s)” error?

跟風遠走 提交于 2019-12-05 10:20:25

Bazel wants you to depend on the headers (i.e., put them in deps). Basically, you should create a cc_library for those headers. Putting headers in hdrs doesn't publicly expose them, it just exposes them to rules that depend on that library (which is exactly what you want). So you'll have:

# third_party/some_lib/BUILD
cc_library(
    name = "headers",
    hdrs = glob(["*.h"]),
    visibility = ["//path/to/package:__pkg__"],
)

Note that you should replace //path/to/package with your actual target's package, but the __pkg__ above is literal: that's how you indicate "visible to that package". Then no other packages can access those headers.

Then add //third_party/some_lib:headers in your target's deps.

The copts are just used to modify C++'s header search paths, not Bazel's. Bazel always assumes that you'll do #include "path/relative/to/your/workspace/dir.h", but if you've got a source like:

#include "foo.h"

where foo.h is at third_party/some_lib/includes/foo.h, you could say copts = ["-Ithird_party/some_lib/includes"] to add that to C++'s header search path.

I met similar prolblem "undeclared inclusion(s) in rule", I solved by removing the bazel cache files in /root/.cache/bazel/. Hope helps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!