0

What is the best way to build C++ code that uses the dlib library using Bazel? I.e., what would the BUILD rules look like?

I tried following the answer for OpenCV as follows, but had no luck:

cc_library(
  name = "dlib",
  srcs = glob(["build/dlib/*.so*"]),
  hdrs = glob(["dlib/*.h"]),
  includes = ["include"],
  visibility = ["//visibility:public"], 
  linkstatic = 1,
)
Community
  • 1
  • 1
John Zhang
  • 518
  • 1
  • 5
  • 12

1 Answers1

2

I think I figured it out. Assuming dlib was unzipped to /opt/dlib-19.2 and built in /opt/dlib-19.2/build.

In your WORKSPACE file:

new_local_repository(
  name = "dlib",
  path = "/opt/dlib-19.2",
  build_file = "dlib.BUILD",
)

In dlib.BUILD:

cc_library(
  name = "dlib",
  srcs = glob(["build/dlib/*.so*"]),
  hdrs = glob(["dlib/**/*.h"]),
  includes = ["."],
  visibility = ["//visibility:public"], 
  linkstatic = 1,
)
John Zhang
  • 518
  • 1
  • 5
  • 12