vulkan-go / vulkan

Vulkan API bindings for Go programming language
MIT License
742 stars 55 forks source link

Having trouble linking the MoltenVK framework on macOS #51

Open alansikora opened 3 years ago

alansikora commented 3 years ago

When I run go get "github.com/vulkan-go/vulkan", the framework cannot be found:

~/W/A/go-vulkan-engine ❯❯❯ go get "github.com/vulkan-go/vulkan"                                        ✘ 2
# github.com/vulkan-go/vulkan
ld: framework not found MoltenVK
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I tried copying MoltenVK.xcframework to the /Library/Frameworks folder, symlinking, also with vulkan.framework and I can't make it work.

I also tried to run it with sudo, no luck.

Has anyone run into the same problem?

ptxmac commented 3 years ago

It seems MoltenVK switched to use the new xcframework which is great for packaging multiple static libraries for different platforms - unfortunately, it doesn't play nice with clang.

I was able to work around the problem by using the dylib version of MoltenVK, unfortunately that required me to fork vulkan-go/vulkan and vulkan-go/glfw since there's no way to replace the linking flags.

I've created an issue on the MoltenVK project: https://github.com/KhronosGroup/MoltenVK/issues/1328

But perhaps it would make sense to add a way to select framework or dylib in vulkan_darwin.go. E.g. with a build tag

xlab commented 3 years ago

@ptxmac I'm okay to always follow the bleeding edge. If that's a simple change (and doesn't require full re-gen), then PR is very welcome :)

I don't see the point to use framework version at all..

ptxmac commented 3 years ago

The framework version might be useful for creating iOS / tvOS / etc apps - but it shouldn't be a blocker.

Unfortunately, the MoltenVK project only provides make targets for installing the xcframework. So the installation becomes a bit more manual.

I'll put up some PRs with the changes

ptxmac commented 3 years ago

For vulkan: https://github.com/vulkan-go/vulkan/pull/52

And the same change for glfw: https://github.com/vulkan-go/glfw/pull/6

Nv7-GitHub commented 2 years ago

The Makefile didn't work, however using CGO_CFLAGS="$(pkg-config --cflags glfw3)" CGO_LDFLAGS="-L/usr/local/lib $(pkg-config --libs glfw3)" go build works. (Note the -L/usr/local/lib part)