简体   繁体   中英

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

I'm writing a C++ program using CLion as my IDE and Bazel as my build tool. I need to parse XML and would like to use the xerces-c Apache library. I've set up my WORKSPACE file to create a local repository for the xerces-c shared library:

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"],
)
    """
)

However, I can't convince CLion (which has the bazel plugin installed) to index the header files for xerces-c.

I've tried:

WORKSPACE :

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",
    ],
)

but it didn't help.

Building from the command line works just fine with just the @system_libs//:xercesc dependency. This seems to just be a CLion indexing issue.

Question: how can I convince CLion to look in /usr/local/include/xercesc and index the headers it finds there?

This was actually a bug in bazel 0.28.0 that was causing CLion to fail during indexing. I reverted to 0.27.2 and the problem went away.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM