如何在 CLion 中将外部 C++ 库与 Bazel 一起使用?

How can I use external C++ libraries with Bazel in CLion?

我正在编写一个 C++ 程序,使用 CLion 作为我的 IDE 并使用 Bazel 作为我的构建工具。我需要解析 XML 并想使用 xerces-c Apache 库。我已经设置了我的 WORKSPACE 文件来为 xerces-c 共享库创建一个本地存储库:

new_local_repository(
    name = "system_libs",
    path = "/usr/lib/x86_64-linux-gnu",
    build_file_content = """
cc_library(
    name = "xerces",
    srcs = ["libxerces-c-3.2.so"],
    visibility = ["//visibility:public"],
)
    """
)

但是,我无法说服 CLion(安装了 bazel 插件)为 xerces-c 的 header 文件编制索引。

我试过:

工作空间:

new_local_repository(
    name = "system_headers",
    path = "/usr/local/include",
    build_file_content = """
cc_library(
    name = "xerces",
    hdrs = glob(["xercesc/**/*.hpp"]),
    visibility = ["//visibility:public"],
)
    """
)

BUILD:
cc_library(
    name = "page_parser_lib",
    srcs = ["page_parser.cc"],
    hdrs = ["page_parser.h"],
    deps = [
        "@system_headers//:xerces",
        "@system_libs//:xerces",
    ],
)

但没有用。

从命令行构建只需要 @system_libs//:xercesc 依赖项就可以正常工作。这似乎只是一个 CLion 索引问题。

问题:我如何说服 CLion 查看 /usr/local/include/xercesc 并索引它在那里找到的 header?

这实际上是 bazel 0.28.0 中的 bug 导致 CLion 在索引期间失败。我恢复到 0.27.2,问题消失了。