我目前正在使用Bazel来构建一个C项目 . 这是我的WORKSPACE文件:
cc_library(
name = "Boost",
srcs = glob(["/usr/local/lib/libboost*.so"]),
hdrs = glob(["/home/duttama/boost_1_55_0/**/*.h"]),
)
cc_library(
name = "OpenCV",
srcs = glob(["/usr/lib/x86_64-linux-gnu/libopencv*.so"]),
hdrs = glob(["/home/duttama/opencv-2.4.13/**/*.h"]),
)
cc_library(
name = "AffectivaSources",
srcs = glob(["/root/affdex-sdk/lib/*.so"]),
hdrs = glob(["/root/affdex-sdk/include/*.h"]),
)
这是我的BUILD文件:
cc_binary(
name = "video-demo",
srcs = ["video-demo.cpp"],
deps = ["//lib:OpenCV",
"//lib:AffectivaSources",
"//lib:Boost",
],
)
当我运行它时,我收到此错误:
ERROR: /root/sdk-samples/WORKSPACE:17:12: Traceback (most recent call last):
File "/root/sdk-samples/WORKSPACE", line 15
cc_library(name = "AffectivaSources", srcs = ..."]), ..."]))
File "/root/sdk-samples/WORKSPACE", line 17, in cc_library
glob
name 'glob' is not defined
我的问题是为什么它没有找到glob函数 . 我不确定还有什么在WORKSPACE文件中指定或如何导入此glob函数 .
1 回答
WORKSPACE文件不适用于
cc_binary
/cc_rules
;它用于定义项目范围的规则,例如外部依赖项,并且在WORKSPACE文件中不提供glob函数 . 有关WORKSPACE规则,请参阅https://docs.bazel.build/versions/master/be/workspace.html .您似乎正在将c依赖项导入项目:请查看
new_local_repository
规则here . 这允许您指向本地系统中的文件夹 . 它将要求您编写包含每个外部依赖项的相应cc_library
规则的BUILD文件 .例如,在您的WORKSPACE文件中:
并在您的项目中,创建
BUILD.affectiva
:完成此操作后,您可以使用以下语法在BUILD文件中依赖它们:
我也看到你在
srcs
/hdrs
属性中使用绝对文件路径 - glob模式不能是绝对的 . 请在此处参考BUILD文件目标标签语法:https://docs.bazel.build/versions/master/build-ref.html#lexi如果您在Bazel存储库中're still confused, there'是一个示例c项目:https://github.com/bazelbuild/bazel/tree/master/examples/cpp