背景
我在使用 cl 编译 C++ 的 Bazel 构建 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
?