file not found with <angled> include; use "quotes" instead

295 views
Skip to first unread message

Yesudeep Mangalapilly

unread,
Jul 29, 2020, 9:42:09 PM7/29/20
to bazel-discuss
Hi,

I'm trying to integrate Bazel into an existing repository that uses
CMake and <angled> includes. We'd prefer to maintain the angled 
includes within the library. However, I'm not sure whether
that would work with the rules I have here:

cc_library(
    name = "foo",
    hdrs = glob([
        "foo/**/*.hpp",
    ]),
    copts = foo_COPTS,
    defines = FOO_DEFINES + [
        "FOO_A=1",
        "FOO_B=0",
    ],
    include_prefix = "foo",
    linkstatic = True,
    strip_include_prefix = "foo",
    visibility = ["//visibility:public"],
)

While this works for the users of this BUILD.bazel rule,
it causes an error when the library author attempts to compile
the library. The error produced is as follows:

test/a/b.cpp:N:M: error: 'foo/meow/cat.hpp' file not found with <angled> include; use "quotes" instead

Essentially, Bazel library users can use the library, but the library maintainer 
cannot unless we switch entirely to using quotes. Is there an easy fix for this?
How does one attempt to use <angled> brackets within the library
but still cater to external users who wish to use Bazel?

Thank you. :)

Cheers,
Y.

Yesudeep Mangalapilly

unread,
Jul 29, 2020, 9:46:27 PM7/29/20
to bazel-discuss
Also, would switching to quotes affect the installability of the library?

Dionna Amalie Glaze

unread,
Jul 29, 2020, 10:09:06 PM7/29/20
to Yesudeep Mangalapilly, bazel-discuss
If you add an "includes" field, then the paths you add there will be transitively added to all dependencies as "-isystem" path flags, which allow you to use angle brackets and omit the path prefix that is searched in -isystem paths.

I'm a little confused why you strip foo as a prefix and then add it back. Probably an artifact of providing a contrived example build rule, so I won't dwell on it.

I don't know the answer to your installability question.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/37e33d7b-ac17-4f65-96e4-a8c8e011674cn%40googlegroups.com.


--
-Dionna Glaze, PhD (she/her)

Yesudeep Mangalapilly

unread,
Jul 29, 2020, 10:46:23 PM7/29/20
to bazel-discuss
Hi Dionna,

Thank you for the quick response! That helps indeed.

Just a side note. The library houses its included directory 'foo' directly in the root of the workspace, so
I had to work around being unable to use `includes = ["."]` by creating an "include" directory in 
the workspace directory, symlinking 'foo' within 'include' as 'include/foo', and using includes = ["include"]
as an additional field.

The new rule now looks like:

cc_library(
    name = "foo",
    hdrs = glob([
        "include/foo/**/*.hpp",
    ]),
    ...
    includes = ["include"],
    linkstatic = True,
    visibility = ["//visibility:public"],
)

Gregg Reynolds

unread,
Jul 29, 2020, 11:30:42 PM7/29/20
to Yesudeep Mangalapilly, bazel-discuss
Bazel adds -iquote for include paths, which is why the < > includes are not found.  This is correct, since angled includes are only for system headers.  You can use the includes directive, but that may have undesirable effects, since those get added to anything that depends on your lib.  You can also just add -I directives to copts to get the same effect, only local.

The best solution is to use quoted include paths.  If you don't (or can't, if you don't control the code) you will have to add -Iexternal/foo/bar (or an includes directive) everywhere in order to make your lib importable via http_archive or other repo rule.

HTH,

Gregg
 
Reply all
Reply to author
Forward
0 new messages