gpt4 book ai didi

c++ - OSX 上的 GLFW + Vulkan

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:42:52 25 4
gpt4 key购买 nike

我正在为我的一个项目设置 GLFW 和 Vulkan。对于 Vulkan,我使用 MoltenVk 获取 Vulkan compat 并使用 GLFW 来创建窗口。我使用的IDE是CLion,它使用CMake系统。

从一些 github 问题来看,似乎有支持这种设置,但没有人提到它是如何完成的。

GLFW 是通过自制软件和 MoltenVK 手动安装的,方法是将 MoltenVK 和 vulkan 文件夹添加到 usr/local/include 并将 MacOS 文件夹的内容添加到 usr/local/lib(尽管我很确定 MoltenVK.framework 不应该是那里)。

此时,Clion 可以看到 GLFW 和 Vulkan header ,但我仍然需要将它们正确链接起来。

现在完整的 CMakeLists.txt 文件是这样的:

cmake_minimum_required(VERSION 3.8)
project(VulkanEngine)

#set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} “${CMAKE_SOURCE_DIR}/cmake/Modules”)

set(CMAKE_CXX_STANDARD 17)

set(SOURCE_FILES src/main.cpp)
add_executable(VulkanEngine ${SOURCE_FILES})

#Finding and linking GLFW3

find_package(glfw3 3.2 REQUIRED)
if (glfw3_FOUND)
include_directories(${glfw3_INCLUDE_DIRS})
target_link_libraries (VulkanEngine ${glfw3_LIBRARIES})
endif (glfw3_FOUND)

#Finding and linking Vulkan

find_package (Vulkan)
if (Vulkan_FOUND)
include_directories(${Vulkan_INCLUDE_DIRS})
target_link_libraries (VulkanEngine ${Vulkan_LIBRARIES})
endif (Vulkan_FOUND)

当重新加载 cmake 项目时,控制台会显示以下信息:

-- Could NOT find Vulkan (missing:  Vulkan_LIBRARY) 
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/mtesseract/dev/cpp/VulkanEngine/cmake-build-debug

对我来说,这表明已经找到并链接了 GLFW,但是当我尝试为 GLFW 构建“hello world”时,我收到以下消息:

Undefined symbols for architecture x86_64:
"_glfwInit", referenced from:
_main in main.cpp.o

我从 GLFW github 页面获得了 FindVulkan.cmake https://git.io/v5ggN ,因为它支持 MoltenVK,但我不确定它是否被 CMake 完全接受。 (我把文件放在(projectroot)/cmake/modules/)

在这一点上,我不知道为什么链接不正确,所以非常感谢您的帮助。

最佳答案

我找到了一个至少在某种程度上似乎有效的解决方案。此时我还有另一个问题需要处理(GLFW 似乎没有注意到 MoltenVK 的存在)。

到目前为止的过程如下(可以在我的 github 页面 (github.com/mtesseracttech/VulkanEngine) 上找到):

Vulkan + GLFW + GLM Setup Process with CMake and Package Managers

Windows:

Preparation:
Create CLion Application Project
Install MSYS2 (Cygwin-like package manager that includes a windows port of Arch's PacMan)
Install LunarG VK SDK
Download FindVulkan.cmake from GFLW's Github (it includes a path for MoltenVK(for OSX Later)) and put it in (proj_root/cmake/modules)

MSYS2 Commands:

$ pacman -Su //Updates pacman
$ pacman -Ss {packageName} //Is used for searching for exact package names

Installed Packages through msys2:

$ pacman -S mingw-w64-x86_64-toolchain //Installs the CLion toolchain that includes CMake, Make, GCC, etc.
$ pacman -S mingw-w64-x86_64-glfw //Installs GLFW
$ pacman -S mingw-w64-x86_64-glm //Installs GLM
$ pacman -S mingw-w64-x86_64-vulkan //Vulkan can also be installed through this method, but I went with LunarG

Enter the following in the CMakeLists.txt file in the root of the project:

######################################################################################

cmake_minimum_required(VERSION 3.8)
project(VulkanEngine)

set(CMAKE_CXX_STANDARD 17)

set(SOURCE_FILES src/main.cpp)
add_executable(VulkanEngine ${SOURCE_FILES})

#Setting up PkgConfig

find_package(PkgConfig REQUIRED)

#Finding and linking GLFW3

pkg_search_module(GLFW3 3.2 REQUIRED glfw3)
if(GLFW3_FOUND)
message(STATUS "Found GLFW, Including and Linking now")
include_directories(${GLFW3_INCLUDE_DIRS})
target_link_libraries(VulkanEngine ${GLFW3_STATIC_LIBRARIES})
endif(GLFW3_FOUND)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")

#Finding and linking Vulkan

find_package (Vulkan)
if (VULKAN_FOUND)
message(STATUS "Found Vulkan, Including and Linking now")
include_directories(${VULKAN_INCLUDE_DIR})
target_link_libraries (VulkanEngine ${VULKAN_LIBRARY})
endif (VULKAN_FOUND)

######################################################################################




OSX:

Preparation

Create CLion Application Project
Install HomeBrew (package manager)
Download MoltenVK
Download FindVulkan.cmake from GFLW's Github (it includes a path for MoltenVK(for OSX Later)) and put it in (proj_root/cmake/modules)

Homebrew:
brew update //Updates homebrew
brew install glfw //Installs GLFW
brew install glm //Installs GLM

MoltenVK:
Place MoltenVK/macOS's contents into /usr/local/lib
Place MoltenVK/macOS/MoltenVK.framework/headers's contents into /usr/local/inc/MoltenVK

CMake:
Same as on windows, but in the FindVulkan.cmake file, add at the very end of the elseif(APPLE) block the line:
set(VULKAN_INCLUDE_DIR "/usr/local/include/MoltenVK")
This is not a pretty or flexible solution, but for now it will do.

我很确定这个解决方案并不理想,因为 GLFW 没有采用这种策略来处理 MoltenVK,但至少可以编译,所以我认为这是进步。

关于c++ - OSX 上的 GLFW + Vulkan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46059565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com