错误是
.../demo.cc:5:10: fatal error: 'city.h' file not found
#include <city.h>
cityhash
由brew install cityhash
安装。city.h
可以在/usr/local/include
中找到。而且,它实际上在
clang
的搜索路径中。$ clang -E -xc++ - -v
Apple LLVM version 10.0.1 (clang-1001.0.46.3)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.14.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name - -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=10.14 -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 450.3 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I/usr/local/include -stdlib=libc++ -Wno-atomic-implicit-seq-cst -Wno-framework-include-private-from-public -Wno-atimport-in-framework-header -Wno-quoted-include-in-framework-header -fdeprecated-macro -fdebug-compilation-dir /Users/formath/git/mlp -ferror-limit 19 -fmessage-length 202 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx-10.14.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o - -x c++ -
clang -cc1 version 10.0.1 (clang-1001.0.46.3) default target x86_64-apple-darwin18.2.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.1/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks (framework directory)
我的
Bazel
版本是1.1.0
。我看到了一个相同的问题,目前尚未解决。
https://github.com/bazelbuild/bazel/issues/5391
最佳答案
作为一种解决方法,您可以为cc_library
添加new_local_repository
,以在/usr/local
上包装 View 。
在您的WORKSPACE
文件中,定义一个new_local_repository
,并将path
属性设置为/usr/local
,并将build_file
指向工作空间本地的BUILD
文件,例如:
# WORKSPACE
new_local_repository(
name = "usr_local",
path = "/usr/local",
build_file = "third_party/usr_local.BUILD",
)
对于要包装的不同库,
third_party/usr_local.BUILD
文件可能具有不同的规则。对于cityhash
,您可以执行以下操作(我不知道cityhash
库的结构,因此我在这里猜测.so
):# third_party/usr_local.BUILD
cc_library(
name = "cityhash",
hdrs = glob(["include/cityhash/**"]),
srcs = [
"lib64/cityhash.so",
],
includes = [
"include/cityhash",
],
visibility = ["//visibility:public"],
)
请注意,这些路径将相对于新的本地存储库位置(因此在本例中为
/usr/local
)。最后,在
BUILD
文件中,您可以使用以下方式引用cityhash
targetu:# BUILD
cc_binary(
name = "main",
srcs = [
"main.cc",
],
deps = [
"@usr_local//:cityhash",
],
)
希望这可以帮助。
关于c++ - 为什么bazel不搜索系统包含路径,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58908156/