簡體   English   中英

在 macOS (Bazel) 上找不到 GLFW 庫

[英]Cannot find GLFW library on macOS (Bazel)

我正在使用 C++、Bazel 和 GLFW 開發一個簡單的 OpenGL 應用程序。 當我嘗試為我的應用程序構建規則時,我收到以下錯誤消息:

ld: library not found for -lglfw3

我的環境:

  • macOS Catalina 10.15.7
  • 蘋果叮當版 12.0.0

這是我針對目標的BUILD規則:

cc_binary(
    name = "hello-glfw",
    srcs = ["hello-glfw.cpp"],
    deps = [
        "@glfw//:glfw",
    ],
)

我正在嘗試將 GLFW 構建為外部依賴項。 我的WORKSPACE文件有這個:

http_archive(
    name = "glfw",
    build_file = "@//extern:glfw.BUILD",
    strip_prefix = "glfw-3.3.2",
    urls = ["https://github.com/glfw/glfw/archive/3.3.2.zip"],
)

我的glfw.BUILD文件的內容是:

DARWIN_DEFINES = [
    "_GLFW_COCOA",
    "_GLFW_NSGL",
    "_GLFW_NO_DLOAD_WINMM",
    "_GLFW_USE_OPENGL",
]

DARWIN_HDRS = [
    "src/cocoa_joystick.h",
    "src/cocoa_platform.h",
    "src/glx_context.h",
    "src/nsgl_context.h",
    "src/null_joystick.h",
    "src/null_platform.h",
    "src/posix_thread.h",
    "src/wl_platform.h",
]


DARWIN_SRCS = [
    "src/cocoa_time.c",
    "src/posix_thread.c",
]

DARWIN_LINKOPTS = [
    "-lglfw3",
    "-framework OpenGL",
    "-framework Cocoa",
    "-framework IOKit",
    "-framework CoreFoundation"
]


cc_library(
    name = "glfw_src",
    hdrs = [
        "include/GLFW/glfw3.h",
        "include/GLFW/glfw3native.h",
        "src/egl_context.h",
        "src/internal.h",
        "src/osmesa_context.h",
        "src/mappings.h",
        "src/xkb_unicode.h",
    ] + select({
        "@bazel_tools//src/conditions:windows": WIN32_HDRS,
        "@bazel_tools//src/conditions:linux_x86_64": LINUX_HDRS,
        "@bazel_tools//src/conditions:darwin": DARWIN_HDRS,
    }),
    srcs = [
        "src/context.c",
        "src/egl_context.c",
        "src/init.c",
        "src/input.c",
        "src/osmesa_context.c",
        "src/monitor.c",
        "src/vulkan.c",
        "src/window.c",
        "src/xkb_unicode.c",
    ] + select({
        "@bazel_tools//src/conditions:windows": WIN32_SRCS,
        "@bazel_tools//src/conditions:linux_x86_64": LINUX_SRCS,
        "@bazel_tools//src/conditions:darwin": DARWIN_SRCS,
    }),
    defines = select({
        "@bazel_tools//src/conditions:windows": WIN32_DEFINES,
        "@bazel_tools//src/conditions:linux_x86_64": LINUX_DEFINES,
        "@bazel_tools//src/conditions:darwin": DARWIN_DEFINES,
    }),
)

cc_library(
    name = "glfw",
    hdrs = [
        "include/GLFW/glfw3.h",
        "include/GLFW/glfw3native.h",
    ],
    linkopts = select({
        "@bazel_tools//src/conditions:windows": WIN32_LINKOPTS,
        "@bazel_tools//src/conditions:linux_x86_64": LINUX_LINKOPTS,
        "@bazel_tools//src/conditions:darwin": DARWIN_LINKOPTS,
    }),
    deps = [":glfw_src"],
    strip_include_prefix = "include",
    visibility = ["//visibility:public"],
)

我認為您只需要從代碼塊中刪除-lglfw3

DARWIN_LINKOPTS = [
    "-lglfw3",
    "-framework OpenGL",
    "-framework Cocoa",
    "-framework IOKit",
    "-framework CoreFoundation"
]

所以它寫道:

DARWIN_LINKOPTS = [
    "-framework OpenGL",
    "-framework Cocoa",
    "-framework IOKit",
    "-framework CoreFoundation"
]

glfw3 鏈接請求可能是針對預構建的 glfw 構建指令的剪切和粘貼錯誤。

我在 Mac 上遇到了同樣的問題。 我為 GLFW 找到的 Bazel 規則在 Mac OS 上對我不起作用,所以我決定重寫它們。 在遇到幾個鏈接錯誤后,我設法讓它完全正常工作,並在此處報告了我的發現。 我想你現在已經設法解決了你的問題,但我希望它對遇到這個問題的其他人有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM