如何通过 mingw-w64 运行 windows 中的 vulkan 示例代码?

How to run vulkan example code in windows by mingw-w64?

大家。 我最近开始在 window 笔记本电脑上学习 vulkan sdk 编程。我下载了VulkanSDK-1.2.162.0,x86_64-8.1.0-release-win32-seh-rt_v6-rev0和glfw-3.3.2.bin.WIN64,解压并设置windows路径,就大功告成了并像这样在 cmd 中显示测试结果:

C:\Users\Administrator>g++ --version
g++ (x86_64-win32-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
C:\Users\Administrator>vulkaninfo
==========
VULKANINFO
==========

Vulkan Instance Version: 1.2.154


Instance Extensions: count = 11
===============================
        VK_EXT_debug_report                    : extension revision 9
        VK_EXT_debug_utils                     : extension revision 2
        VK_EXT_swapchain_colorspace            : extension revision 4
......
......
......

我是c/c++编程初学者,在我对c/c++编译器工作流程的基本理解中,它需要头文件路径和库路径。所以,我尝试在我的机器上使用 g++ 命令 运行 vulkan 的官方 cpp code,如下所示:

g++ -std=c++11 vlkantest.cpp -I D:\Other\Vulkan\SDK_ROOT\1.2.162.0\Include -I D:\Other\mingw64\include -I D:\Other\glfw-3.3.2.bin.WIN64\include -L D:\Other\Vulkan\SDK_ROOT\1.2.162.0\Lib -L D:\Other\mingw64\lib -L D:\Other\glfw-3.3.2.bin.WIN64\lib-mingw-w64

但是,我得到的结果是这样的:

g++ -std=c++11 vlkantest.cpp -I D:\Other\Vulkan\SDK_ROOT\1.2.162.0\Include -I D:\Other\mingw64\include -I D:\Other\glfw-3.3.2.bin.WIN64\include -L D:\Other\Vulkan\SDK_ROOT\1.2.162.0\Lib -L D:\Other\mingw64\lib -L D:\Other\glfw-3.3.2.bin.WIN64\lib-mingw-w64
C:\Users\ADMINI~1\AppData\Local\Temp\ccdv6xfT.o:vlkantest.cpp:(.text$_ZN24HelloTriangleApplication10initWindowEv[_ZN24HelloTriangleApplication10initWindowEv]+0xd): undefined reference to `glfwInit'
C:\Users\ADMINI~1\AppData\Local\Temp\ccdv6xfT.o:vlkantest.cpp:(.text$_ZN24HelloTriangleApplication10initWindowEv[_ZN24HelloTriangleApplication10initWindowEv]+0x1c): undefined reference to `glfwWindowHint'
C:\Users\ADMINI~1\AppData\Local\Temp\ccdv6xfT.o:vlkantest.cpp:(.text$_ZN24HelloTriangleApplication10initWindowEv[_ZN24HelloTriangleApplication10initWindowEv]+0x2b): undefined reference to `glfwWindowHint'
C:\Users\ADMINI~1\AppData\Local\Temp\ccdv6xfT.o:vlkantest.cpp:(.text$_ZN24HelloTriangleApplication10initWindowEv[_ZN24HelloTriangleApplication10initWindowEv]+0x50): undefined reference to `glfwCreateWindow'
C:\Users\ADMINI~1\AppData\Local\Temp\ccdv6xfT.o:vlkantest.cpp:(.text$_ZN24HelloTriangleApplication8mainLoopEv[_ZN24HelloTriangleApplication8mainLoopEv]+0x17): undefined reference to `glfwWindowShouldClose'
C:\Users\ADMINI~1\AppData\Local\Temp\ccdv6xfT.o:vlkantest.cpp:(.text$_ZN24HelloTriangleApplication8mainLoopEv[_ZN24HelloTriangleApplication8mainLoopEv]+0x25): undefined reference to `glfwPollEvents'
C:\Users\ADMINI~1\AppData\Local\Temp\ccdv6xfT.o:vlkantest.cpp:(.text$_ZN24HelloTriangleApplication7cleanupEv[_ZN24HelloTriangleApplication7cleanupEv]+0x17): undefined reference to `glfwDestroyWindow'
C:\Users\ADMINI~1\AppData\Local\Temp\ccdv6xfT.o:vlkantest.cpp:(.text$_ZN24HelloTriangleApplication7cleanupEv[_ZN24HelloTriangleApplication7cleanupEv]+0x1c): undefined reference to `glfwTerminate'
collect2.exe: error: ld returned 1 exit status

我想我错过了 g++ 的一些参数,有人可以指出我在上面的 g++ 命令中的错误吗?或者只是简单地解释这个示例代码是如何通过 mingw-w64 在 windows 中编写 运行 的? 非常感谢!

您似乎指定了库文件夹,但实际上并未链接这些库。您是否尝试过将 -lglfw3 -lvulkan-1 添加到您的编译命令?