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

标签 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 cc_library 的论据.

我尝试了另一个技巧,我看到您通过 Bazel 中的另一个仓库编辑 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"]),
)
""",

问题是,如果我将该 repo 作为 deps 引用到我尝试构建的外部库,我会收到以下错误:
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"

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

我该怎么办?
我不明白为什么我不能向 copt 添加系统路径(可能是密封原因)。我不知道如何包含路径并将它们作为系统 header 访问。我用 -isystem 尝试了不同的东西也一样,但看到了同样的错误。

最佳答案

正如 László 所说,您可以设置 includes到当前目录,当用作其他代码的依赖项时,这将允许它被检测为系统 header :

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

关于c++ - 如果 copts 不允许系统路径,如何引用外部依赖项使用的系统库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51408079/

相关文章:

tensorflow - 从源代码构建 Tensorflow 时,编译是从头开始还是在修复错误后继续?

c++ - 在条件之外使用比较运算符

c++ - 对 `std::ostream& SpyOutput::operator<<<double>(double const&)' 的 undefined reference

c++ - 尝试在 C++ 中使用 glDrawArrays 时出错

C++/巴泽尔 : How to include angle <> bracket system headers?

bazel - 使用 bazel 时,如何让 protobuf 方法在 intellij 中解析?

c++ - 在Win10上用VS2015编译的C++ SDL2程序调试加载时间错误

c++ - 使用 OpenCV、C++ 和 Image 2D 进行头部姿势估计 - 几何方法 - 滚动、偏航和俯仰

c++ - SDL - 动态阿尔法?

c - SDL 事件内存泄漏