如果 copts 不允许系统路径,如何引用外部依赖项使用的系统库?
How do I reference a system library used by an external dependency if copts doesn't allow system paths?
对于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:
copts = ["-Iexamples/", "-D_REENTRANT", "-I/usr/include/SDL"],
但错误是:
The include path '/usr/include/SDL' references a path outside of the execution root.
好的。如果我尝试将其添加到cc_library
的includes
参数中,也是如此。
我尝试了我看到的另一个技巧,通过Bazel中的另一种repo编辑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"
当然,我不能把标题改成那样,因为这不是我的标题。它来自我拆除的外部图书馆。
我该怎么办
我不明白为什么我不能为copts添加系统路径(可能是封闭的原因(。我不知道如何包含路径并将其作为系统头进行访问。我也用-isystem
尝试了不同的东西,但看到了相同的错误。
正如László所说,您可以将includes
设置为当前目录,这将允许在其他代码中用作依赖项时将其检测为系统标头:
cc_library(
...
includes = [
".",
],
)
相关文章:
- 使用 Git 处理 C++ Visual Studio 2019 解决方案的外部依赖项源代码管理的最佳方法是什么?
- 如何将外部依赖引入跨平台CMake项目?
- 当 lib 已添加到其他依赖项时,如何在 VS 中调试未解析的外部符号错误
- 使用 cmake 获取外部依赖关系
- CMake 外部和内部静态库的循环依赖关系
- 如何在bazel中同时处理外部依赖项和我的项目
- 如果 copts 不允许系统路径,如何引用外部依赖项使用的系统库?
- 使用外部依赖项运行 VC++ 单元测试时"Failed to set up execution context"
- 无法构建外部库依赖项
- 如何忽略来自 Bazel 中的外部C++依赖项标头的警告
- CMake 和外部依赖关系
- 使用 CMake 外部项目为跨平台库依赖项的目标名称
- 是否可以编译具有在编译时无法解析的外部依赖项的静态库?
- C++项目文件夹外部依赖项仅包含 .h 和 .hpp 文件
- 如何避免#crude依赖外部库
- 在Visual Studios 2010的外部依赖项文件夹中搜索文本/代码
- visualstudioc++的外部依赖关系
- 如何在VS2015中将外部库依赖项链接到一个静态库文件中
- 如何测试从依赖于外部系统的外部基类派生的类
- 在命名空间前缀解析和优化级别依赖关系中使用外部"C" C++