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

标签 c++ clion bazel

我正在编写一个 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 的头文件。

我试过:

工作空间:

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 ?

最佳答案

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

关于c++ - 如何在 CLion 中将外部 C++ 库与 Bazel 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57066146/

相关文章:

c++ - 如何修复错误 "other computer the program can' t start because libgcc_s_dw2-1.dll is missing from your computer“在其他计算机上

c++ - Clion "Cannot load CMake project: CMake executable is incorrect"问题

c++ - 如何使用 `cc_common.create_link_variables` API?

build - cmake 到 bazel - cppyy - 共享库和包含路径

go - Bazel 没有将 BUILD 文件添加到外部依赖项

c++ - 带链接字符串的 Ncurses 菜单

c++ - 如何让函数在主循环之外继续循环,直到按下按钮

java - 程序退出时的 JNA 错误

c++ - 将 shared_ptr 参数添加到容器的有效方法?

使用 CLion 的 GDB 远程调试不起作用