I have the following structure:
C -
app -
test_opencv.cpp
BUILD
thirdparty -
opencv -
lib
include -
opencv4 -...
BUILD
I have compiled the opencv library by hand using cmake and all includes are under include and the static libraries are under lib.
I have created a BUILD file that looks like this:
load("@rules_cc//cc:defs.bzl","cc_library")
cc_library(
name = "opencv",
srcs = glob(["opencv/lib/**/*.a"]),
hdrs = glob(["opencv/include/opencv4/**"]),
visibility = ["//visibility:public"],
)
Then in my app folder I have the following BUILD for my src file:
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
cc_library(
name = "opencv_deps",
linkopts = [
"-ldl",
"-lz",
"-lpthread",
"-lavutil",
"-lavformat",
"-lavcodec",
"-lswscale",
"-L/opt/homebrew/opt/ffmpeg/lib",
"-L/opt/homebrew/Cellar/libx11/1.8.6/lib",
"-framework Cocoa",
"-framework Accelerate",
"-framework CoreMedia",
"-framework CoreVideo",
"-framework AVFoundation"
],
deps = [
"//C/thirdparty/opencv:opencv",
]
)
cc_binary(
name = "test_opencv",
srcs = ["test_opencv.cpp"],
deps = [
":opencv_deps",
"//C/thirdparty/rerunner:rerunner",
],
copts = [
# "-IC/thirdparty/opencv/opencv/include/opencv4",
"--std=c++17"
],
)
With this I get fatal error: 'opencv2/core.hpp' file not found #include <opencv2/core.hpp>.
If I comment out the include to opencv4 it works.
But this does not feel correct. I think it should be enough to use deps = ["//C/thirdparty/opencv:opencv"] to get the header files.
UPDATE
Adding includeshelped:
cc_library(
name = "opencv",
srcs = glob(["opencv/lib/**/*.a"]),
hdrs = glob(["opencv/include/opencv4/**"]),
includes = ["opencv/include/opencv4"],
visibility = ["//visibility:public"],
)