要解决Bazel中配置C/C++构建的方式,可以参考以下步骤和代码示例:
cc_library(
name = "my_library",
srcs = ["my_file.cpp"],
hdrs = ["my_header.h"],
includes = ["path/to/includes"],
deps = [
"//path/to/dependency:library",
],
)
workspace(name = "my_workspace")
http_archive(
name = "rules_cc",
urls = ["https://github.com/bazelbuild/rules_cc/archive/0.2.0.tar.gz"],
sha256 = "abcdef123456...",
)
load("@rules_cc//cc:repositories.bzl", "rules_cc_dependencies")
rules_cc_dependencies()
build --cxxopt="-std=c++17"
build --linkopt="-lmy_library"
bazel build //path/to/target:target_name
其中,//path/to/target:target_name
是你要编译的目标文件路径和名称。
这些步骤和代码示例可以帮助你配置C/C++构建方式。你可以根据实际需求进行调整和修改。