summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2023-12-20 10:48:03 -0800
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2023-12-20 10:48:03 -0800
commit5b6846850813bee24f0fb13f340c05ebe9498ff6 (patch)
treeecba803f167cf211313700bcd5807d8e9e0f64f7
parent816998ea1e6b6546bc24d912478708219494962c (diff)
downloadvolk-5b6846850813bee24f0fb13f340c05ebe9498ff6.tar.gz
Fall back to /usr/local/lib/libvulkan.dylib on macOS
dlopen on macOS is supposed to automatically search /usr/local/lib per dlopen man page. This behavior is customizable via DYLD_LIBRARY_PATH and DYLD_FALLBACK_LIBRARY_PATH, but even if neither is explicitly set /usr/local/lib should be a search path. Unfortunately, this does not happen anymore on modern macOS systems, and this is precisely where Vulkan SDK installs dylib by default. This used to "work" in CMake builds that accidentally linked in libvulkan.dylib statically, because the library was already loaded into the process, but fixing that exposed this issue. For now we need to manually fallback to /usr/local/lib path.
-rw-r--r--volk.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/volk.c b/volk.c
index 85fb0a7..5c0c2ed 100644
--- a/volk.c
+++ b/volk.c
@@ -68,6 +68,10 @@ VkResult volkInitialize(void)
module = dlopen("libvulkan.1.dylib", RTLD_NOW | RTLD_LOCAL);
if (!module)
module = dlopen("libMoltenVK.dylib", RTLD_NOW | RTLD_LOCAL);
+ // modern versions of macOS don't search /usr/local/lib automatically contrary to what man dlopen says
+ // Vulkan SDK uses this as the system-wide installation location, so we're going to fallback to this if all else fails
+ if (!module)
+ module = dlopen("/usr/local/lib/libvulkan.dylib", RTLD_NOW | RTLD_LOCAL);
if (!module)
return VK_ERROR_INITIALIZATION_FAILED;