我正在为我的一个项目设置GLFW和Vulkan。对于Vulkan,我使用MoltenVk来获取Vulkan compat和GLFW来创建窗口。我使用的集成开发环境是使用CMake系统的CLion。
从github的一些问题来看,似乎有人支持这种设置,但没有人提到它是如何实现的。
GLFW是通过homebrew和MoltenVK手动安装的,方法是将MoltenVK和vulkan文件夹添加到usr/local/include,并将MacOS文件夹的内容添加到usr/local/lib (尽管我非常确定MoltenVK.framework不应该在那里)。
在这一点上,Clion可以看到GLFW和Vulkan头,但我仍然需要将它们正确地链接起来。
完整的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页面https://git.io/v5ggN获得了FindVulkan.cmake,因为它支持MoltenVK,但我不确定它是否会被CMake采用。(我将文件放在(Projectroot)/cmake/modules/中)
在这一点上,我不知道为什么事情没有正确链接,所以感谢你的帮助。
发布于 2017-09-11 23:14:24
我已经找到了一个解决方案,至少在某种程度上看起来是有效的。在这一点上,我有另一个问题要解决(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,但至少事情是可以编译的,所以我认为这是一种进步。
发布于 2018-11-13 02:00:25
您的问题似乎是您还没有定义VULKAN_SDK变量。确保将其指向SDK中的/lib & /include的父文件夹,FindVulkan应该可以工作
VULKAN_SDK=/opt/vulkan/x86_64 cmake.
https://stackoverflow.com/questions/46059565
复制相似问题