c++ - 在 macOS (Bazel) 上找不到 GLFW 库
问题描述
我正在使用 C++、Bazel 和 GLFW 开发一个简单的 OpenGL 应用程序。当我尝试为我的应用程序构建规则时,我收到以下错误消息:
ld: library not found for -lglfw3
我的环境:
- macOS 卡塔利娜 10.15.7
- 苹果clang版本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"],
)
解决方案
我在 Mac 上遇到了同样的问题。我为 GLFW 找到的 Bazel 规则在 Mac OS 上对我不起作用,所以我决定重写它们。在遇到几个链接错误后,我设法让它完全正常工作,并在这里报告了我的发现。我想你现在已经设法解决了你的问题,但我希望它对遇到这个问题的其他人有用。
推荐阅读
- java - Elastic 6.5 不支持 IndexRequest
- node.js - Will my websocket server affect nodejs server?
- ios - Display saved time in UIDatePicker after re-run app
- tsql - 在另一个存储过程中使用存储过程中的值
- kotlin - Kotlin convert Map
to Map > - php - 隐藏表格中的多个子行
- jenkins - Need to deploy to staging
- javascript - 如何将值从 angular .ts 文件传输到 javascript .js 文件
- .net - Writing a regex for a pattern like CA123456SDL or CA123456
- alexa - 从 alexa 技能中调用 alexa 技能