我试图使用Bazel编译和分发基于OpenCV的C ++代码,而我正面临一个无法解决的问题。
我在Ubuntu 16.04 LTS上从源代码构建和安装OpenCV 3.3,并支持CUDA(CUDA 8)。我将它安装在标准目录/ usr / local。
中鉴于此,我使用此WORKSPACE文件创建了我的项目:
new_local_repository(
name = "opencv",
path = "/usr/local",
build_file = "opencv.BUILD",
)
opencv.BUILD包含:
cc_library(
name = "opencv",
srcs = glob(["lib/*.so*"]),
hdrs = glob(["include/**/*.hpp"]),
includes = ["include"],
visibility = ["//visibility:public"],
linkstatic = 1,
)
我可以在我自己的代码中使用它:
cc_binary(
name = "main",
srcs = ["main.cc"],
deps = [
"@opencv//:opencv"
],
)
但OpenCV中的一些源文件,如:
/usr/local/include/opencv2/flann/flann_base.hpp
包含来自同一目录的头文件,例如:
#include "general.h"
当我用Bazel构建时,我收到了这个错误:
ERROR: /home/damien/main/BUILD:1:1: C++ compilation of rule '//main:main' failed (Exit 1)
In file included from external/opencv/include/opencv2/flann.hpp:48:0,
from external/opencv/include/opencv2/opencv.hpp:62,
from main/main.cc:1:
external/opencv/include/opencv2/flann/flann_base.hpp:38:21: fatal error: general.h: No such file or directory
(general.h与flann_base.hpp位于同一目录中。)
如果我将#include指令重写为:
#include "opencv2/flann/general.h"
它汇编得很好。但这不是一个方便的解决方案。
所以我的问题是:有没有办法告诉Bazel在" current"的同一目录中寻找标题?该库中的文件?我看看Bazel的每个C ++指令,但是我没有看到任何可以实现它的东西。
提前谢谢。
答案 0 :(得分:5)
好的,对我感到羞耻。我必须导入* .h:
cc_library(
name = "opencv",
srcs = glob(["lib/*.so*"]),
hdrs = glob(["include/**/*.hpp", "include/**/*.h"]),
includes = ["include"],
visibility = ["//visibility:public"],
linkstatic = 1,
)
答案 1 :(得分:0)
在我使用opencv4和Damien设置的情况下,在包含 highgui.hpp 时出现了错误:
external/opencv/include/opencv4/opencv2/highgui.hpp:46:10: fatal
error: opencv2/core.hpp: No such file or directory #include
"opencv2/core.hpp"
我可以通过调整添加opencv4的内容来修复它:
cc_library(
name = "opencv",
srcs = glob(["lib/*.so*"]),
hdrs = glob(["include/**/*.hpp", "include/**/*.h"]),
includes = ["include/opencv4"],
visibility = ["//visibility:public"],
linkstatic = 1,
)