[英]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 = ["-Iexamples/", "-D_REENTRANT", "-I/usr/include/SDL"],
但錯誤是:
The include path '/usr/include/SDL' references a path outside of the execution root.
好的。 如果我嘗試將其添加到cc_library
的includes
參數中, cc_library
。
我嘗試了另一個技巧,我看到您通過 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"
當然,我不能將標題更改為那個,因為它不是我的標題。 它來自我拉下來的外部庫。
我該怎么辦?
我不明白為什么我不能向 copt 添加系統路徑(可能是密封原因)。 我不知道如何包含路徑並將它們作為系統標頭訪問。 我也用-isystem
嘗試了不同的東西,但看到了同樣的錯誤。
正如 László 所說,您可以將includes
設置為當前目錄,這將允許它在用作其他代碼的依賴項時被檢測為系統標頭:
cc_library(
...
includes = [
".",
],
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.