佬友们好,最近尝试通过重构github上找到的一些OpenGL小游戏来学游戏开发。但是在IDE是CLion的环境下,用cmake和vcpkg搭建简易架子时却报错了,似乎是连接错误。。在这贴下代码和报错,大佬们来帮忙看看
报错(大致的)
C:\Users\a8223\AppData\Local\Programs\CLion\bin\mingw\bin/ld.exe: C:/Users/a8223/CLionProjects/AntWare0/src/main.cpp:6: undefined reference to `__imp__ZN2sf9VideoModeC1Ejjj'
完整代码
CMakeLists.txt
cmake_minimum_required(VERSION 3.27)
project(AntWare0 VERSION 0.1.0)
# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
# 查找所需的依赖包
find_package(GLEW REQUIRED)
find_package(SFML CONFIG REQUIRED
COMPONENTS system window graphics audio)
find_package(GLM REQUIRED)
find_package(assimp CONFIG REQUIRED)
find_package(RapidJSON REQUIRED)
# 收集源文件
file(GLOB_RECURSE SOURCES
"src/*.cpp"
)
# 创建可执行文件
add_executable(${PROJECT_NAME} ${SOURCES})
# 添加头文件目录
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
)
# 链接所需的库
target_link_libraries(${PROJECT_NAME} PRIVATE
sfml-system
sfml-window
sfml-graphics
sfml-audio
GLEW::GLEW
glm::glm
assimp::assimp
)
# Windows平台特定设置
if(WIN32)
target_compile_definitions(${PROJECT_NAME} PRIVATE
WINDOWS_LEAN_AND_MEAN
NOMINMAX
)
endif()
main.cpp
#include <SFML/Graphics.hpp>
#include <iostream>
int main() {
sf::String text("Hello, World!");
sf::VideoMode mode(800, 600);
sf::RenderWindow window(mode, "My Window");
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
}
window.clear(sf::Color::Black);
window.display();
}
return 0;
}