如果copts不允许系统路径,如何引用外部依赖项使用的系统库?

时间:2018-07-18 17:43:36

标签: c++ sdl bazel imgui

对于Bazel,我是从WORKSPACE中提取一个外部库:

new_http_archive(
      name = "imgui",
      build_file = "deps/BUILD.imgui",
      sha256 = "c457fdc19b4e3aa74deccf6a2d9bc51f0d470b3acd9cc095bf04df16459d6474",
      strip_prefix = 'imgui-1.62',
      url = "https://github.com/ocornut/imgui/archive/v1.62.tar.gz",
)

BUILD.imgui内部,我正在尝试构建它:

cc_library(
 name = "imgui_sdl_opengl3",
 linkopts = ["-ldl", "-lGL", "-L/usr/lib/x86_64-linux-gnu", "-lSDL2", "-lSDL"],
 copts = ["-Iexamples/", "-D_REENTRANT",],
 includes = [".","examples/libs/gl3w"],
 hdrs = [
     "examples/imgui_impl_opengl3.h",
     "examples/libs/gl3w/GL/gl3w.h",
     "examples/imgui_impl_sdl.h",
     "examples/libs/gl3w/GL/glcorearb.h",
 ],
 srcs = [
     "examples/imgui_impl_opengl3.cpp",
     "examples/imgui_impl_sdl.cpp",
     "examples/libs/gl3w/GL/gl3w.c",
 ],
)

问题是找不到#include <SDL.h>
我尝试将其添加到副本中:

 copts = ["-Iexamples/", "-D_REENTRANT", "-I/usr/include/SDL"],

但是错误是:

The include path '/usr/include/SDL' references a path outside of the execution root.

好的。同样,如果我尝试将其添加到includes的{​​{1}}参数中。

我尝试了另一种技巧,我发现您可以通过Bazel中的另一个存储库使标题可见,如下所示编辑cc_library

WORKSPACE

问题是,如果我将该仓库作为自己要构建的外部库的引用,则会出现以下错误:

new_local_repository(
    name = "SDL",
    path = "/usr/include/SDL",
    build_file_content = """
package(
    default_visibility = [
        "//visibility:public",
    ],
)

cc_library(
    name = "headers",
    srcs = glob(["**/*.h"]),
)
""",

我当然不能更改标题,因为它不是我的标题。它来自我拉下的外部库。

我该怎么办?
我不明白为什么我不能将系统路径添加到副本(可能是密封的原因)。我不知道如何包含路径并使它们作为系统标头进行访问。我也尝试过使用external/imgui/examples/imgui_impl_sdl.cpp:38:10: error: 'SDL.h' file not found with <angled> include; use "quotes" instead #include <SDL.h> ^~~~~~~ "SDL.h" 进行其他操作,但是看到了相同的错误。

1 个答案:

答案 0 :(得分:0)

如László所述,您可以将includes设置为当前目录,当在其他代码中用作依赖项时,它将被检测为系统标头:

cc_library(
    ... 
    includes = [
        ".",
    ],
)