我正在尝试将 Vulkan、GLM 和 GLFW 集成到 clion 中。
学习了一些 cmake 之后,我认为这会起作用。
有了这个cmakelists.txt:
cmake_minimum_required(VERSION 3.27)
project(LuxAegisClion)
set(CMAKE_CXX_STANDARD 20)
add_executable(LuxAegisClion main.cpp)
target_include_directories(LuxAegisClion PRIVATE
C:/VulkanSDK/1.3.275.0/Include
C:/Users/guilh/Documents/Libraries/glfw-3.3.9.bin.WIN64/include
C:/Users/guilh/Documents/Libraries/glm
)
link_directories(LuxAegisClion PRIVATE
C:/VulkanSDK/1.3.275.0/Lib
C:/Users/guilh/Documents/Libraries/glfw-3.3.9.bin.WIN64/lib-vc2022
)
target_link_libraries(LuxAegisClion PRIVATE
vulkan-1.lib
glfw3.lib
)
...以及这段代码:
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>
#include <iostream>
int main() {
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow *window = glfwCreateWindow(800, 600, "Vulkan window", nullptr, nullptr);
uint32_t extensionCount = 0;
vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
std::cout << extensionCount << " extensions supported\n";
glm::mat4 matrix;
glm::vec4 vec;
auto test = matrix * vec;
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
...我收到此消息:
====================[ Build | LuxAegisClion | Debug ]===========================
"D:\apps\code apps\CLion\bin\cmake\win\x64\bin\cmake.exe" --build D:\CodingProjects\LuxAegisClion\cmake-build-debug --target LuxAegisClion -j 14
[1/1] Linking CXX executable LuxAegisClion.exe
FAILED: LuxAegisClion.exe
cmd.exe /C "cd . && "D:\apps\code apps\CLion\bin\mingw\bin\G__~1.EXE" -g CMakeFiles/LuxAegisClion.dir/main.cpp.obj -o LuxAegisClion.exe -Wl,--out-implib,libLuxAegisClion.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lvulkan-1 -lglfw3 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
D:\apps\code apps\CLion\bin\mingw\bin/ld.exe: cannot find -lvulkan-1: No such file or directory
D:\apps\code apps\CLion\bin\mingw\bin/ld.exe: cannot find -lglfw3: No such file or directory
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
在@drescherjm提供的帮助下找到了解决方案:
cmake_minimum_required(VERSION 3.27)
project(LuxAegisClion)
set(CMAKE_CXX_STANDARD 20)
add_executable(LuxAegisClion main.cpp)
target_include_directories(LuxAegisClion PRIVATE
C:/VulkanSDK/1.3.275.0/Include
C:/Users/guilh/Documents/Libraries/glfw-3.3.9.bin.WIN64/include
C:/Users/guilh/Documents/Libraries/glm
)
target_link_directories(LuxAegisClion PRIVATE
C:/VulkanSDK/1.3.275.0/Lib
C:/Users/guilh/Documents/Libraries/glfw-3.3.9.bin.WIN64/lib-mingw-w64
)
target_link_libraries(LuxAegisClion PRIVATE
vulkan-1.lib
glfw3.lib
)
基本上切换到支持 mingw 的库,因为这是 clion 正在使用的编译器