Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ GLFW&x2B;OSX上的Vulkan_C++_Macos_Cmake_Glfw_Vulkan - Fatal编程技术网

C++ GLFW&x2B;OSX上的Vulkan

C++ GLFW&x2B;OSX上的Vulkan,c++,macos,cmake,glfw,vulkan,C++,Macos,Cmake,Glfw,Vulkan,我正在为我的一个项目建立GLFW和Vulkan。对于Vulkan,我使用MoltenVk获取Vulkan compat和GLFW来创建窗口。我使用的IDE是CLion,它使用CMake系统 从一些github问题来看,似乎有人支持这种设置,但没有人提到它是如何实现的 GLFW是通过自制和MoltenVK手动安装的,方法是将MoltenVK和vulkan文件夹添加到usr/local/include,将MacOS文件夹的内容添加到usr/local/lib(尽管我很确定MoltenVK.frame

我正在为我的一个项目建立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头,但我仍然需要将它们正确地连接起来

完整的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,因为它支持MoltenVK,但我不确定它是否被cmake接受。(我将文件放入(projectroot)/cmake/modules/)


在这一点上,我不知道为什么事情不能正确连接,因此非常感谢您的帮助。

我找到了一个解决方案,至少在某种程度上看来是可行的。在这一点上,我有另一个问题要处理(GLFW似乎没有注意到MoltenVK的存在)

到目前为止,流程如下(可以在我的github页面(github.com/mtesseractech/vulkanegene)上找到):


我很确定这个解决方案并不理想,因为GLFW并没有用这种策略在MoltenVK上学习,但至少有些东西是可以编译的,所以我认为这是一个进步。

似乎你的问题是你没有定义
VULKAN_SDK
变量。确保你把它指向SDK和FindVulkan中的/lib&/include的父文件夹应该工作


VULKAN\u SDK=/opt/VULKAN/x86\u 64 cmake.

要查找FindVulkan.cmake,您需要设置cmake\u模块路径以包含
cmake/modules/
。您的cmaklist.txt中有该行,但它被注释掉了,因此您必须取消注释。另外,您是否确定
find\u包(glfw3)
set
glfw3_-FOUND
variable而不是
glfw3_-FOUND
one?这取决于您拥有的find脚本,这些脚本通常会记录它们设置的变量。@Tsyvarev我没有在任何地方明确指定脚本,根据您所说的更改,我会让脚本传递glfw3_-FOUND语句(用MESSAGE命令测试)。但奇怪的是,它仍然说_glfwInit是一个未定义的符号。@Eelke我禁用了它,但是找不到Vulkan,因为如果我添加所需的参数来查找_包(Vulkan)它出错了。你知道我应该如何准备MoltenVK的库以便正确地拾取吗?当脚本集
GLFW3_找到
变量时,它可能会设置
GLFW3_库
等等(前缀为大写)。因此,您也需要更新其他命令。这不是解决您的问题的好办法,您不需要msys2来实现此功能。您最初的错误消息是缺少
\u glfwInit
的定义,它与Vulkan的关系较小,而与GLFW的关系更大。您可以使用
message
验证
glfw3\u库的定义吗
是否为非空字符串?另外,
main.cpp
如何确切地包含GLFW头?通过
#include
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.