Bazel build including header failing

15 Views Asked by At

I am writing a header-only library for a binary search algorithm and building it with Bazel. My directory structure is as follows:

my_project/
├── WORKSPACE
├── lib/
│   ├── BUILD
│   └── binary_search.h
└── app/
    ├── BUILD
    └── main.cc

The lib/BUILD contains following code:

# In lib/BUILD
cc_library(
    name = "binary_search",
    hdrs = ["binary_search.h"],
    includes = ["."],
    visibility = ["//visibility:public"],
)

The app/BUILD contains following code:

cc_binary(
    name = "app",
    srcs = ["main.cc"],
    deps = ["//lib:binary_search"],
    copts = ["-Ilib/"],
)

The main.cc includes the header with an angular bracket:

#include <lib/binary_search.h>

I am getting following error:

app/main.cc:1:10: fatal error: lib/binary_search.h: No such file or directory
    1 | #include <lib/binary_search.h>

What is the source of the issue and how to resolve it while keeping the angular bracket in include? Here is the project github:https://github.com/proywm/testProject/tree/main

0

There are 0 best solutions below