【发布时间】:2023-04-01 22:40:01
【问题描述】:
背景
我正在使用 Bazel 使用 cl 编译 C++ 在 Windows 上构建。
文件子集:
third_party/icu/source/common/unicode/schriter.h
third_party/icu/source/common/unicode/utypes.h
third_party/icu/source/common/unicode/stringpiece.h
third_party/icu/source/common/stringpiece.cpp
third_party/icu/BUILD
a/a.cc
a/a.h
a/BUILD
b/cpp/src/strings/stringpiece.h
b/cpp/src/util/uri_utils.h
b/BUILD
schriter.h 拥有#include "unicode/utypes.h"。
uri_utils.h 和 b/cpp/src/strings/stringpiece.h 都有 class StringPiece。 third_party/icu/source/common/unicode/stringpiece.h 有class U_COMMON_API StringPiece : public UMemory
a.cc 指的是StringPiece,其中包括:
#include "b/cpp/util/uri_utils.h"
#include "strings/stringpiece.h"
#include "third_party/icu/source/common/unicode/schriter.h"
a/BUILD:
cc_library(
name = "a",
srcs = ["a.cc"],
hdrs = ["a.h"],
deps = [
"//third_party/icu:common",
"//b:sdk_strings",
],
)
b/BUILD:
cc_library(
name = "sdk_strings",
srcs = [
"cpp/util/uri_utils.cc",
"cpp/src/strings/stringpiece.cc"
],
hdrs = [
"cpp/util/uri_utils.h",
"cpp/src/strings/stringpiece.h",
],
includes = ["cpp/src"],
)
third_party/icu/BUILD:
cc_library(
name = "common",
srcs = [
"source/common/stringpiece.cpp",
"source/stubdata/stubdata.c",
],
hdrs = glob(["**/*.h"]),
)
问题
照原样,构建 third_party/icu:common 失败并出现:
third_party/icu/source/stubdata/stubdata.c(20): fatal error C1083: Cannot open include file: 'unicode/utypes.h': No such file or directory
如果我将copts = ["/Ithird_party/icu/source/common",], 添加到third_party/icu/BUILD,则icu:common 会构建,但目标a 失败:third_party/icu/source/common/unicode/schriter.h(21): fatal error C1083: Cannot open include file: 'unicode/utypes.h': No such file or directory
如果我改为添加 includes = ["source/common",],,则 icu:common 构建但目标 a 失败:
a/a.cc(168): error C2872: 'StringPiece': ambiguous symbol
b/cpp/util/uri_utils.h(24): note: could be 'StringPiece'
third_party\icu\source\common\unicode/stringpiece.h(52): note: or 'icu_54::StringPiece'
源代码使用 cmake 编译得很好,所以我不需要更改源代码。如何更改 BUILD 文件以正确构建此版本?如何让icu 中的所有内容访问unicode 中的标头,但不将unicode/stringpiece.h 暴露给依赖icu 的目标?
【问题讨论】:
标签: c++ visual-c++ build bazel cl