【发布时间】:2020-08-16 19:40:01
【问题描述】:
最近我开始学习 CMake。为了练习,我正在尝试手动链接 SDL2。我知道还有另一种使用find_file 的方法,这很简单。但我想自己动手练习。
当我尝试链接 libSDL2main.a 文件时出现错误(使用 cmd mingw32-make 运行 Makefile)
[ 50%] Linking CXX executable exe0.exe
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -llibSDL2main
collect2.exe: error: ld returned 1 exit status
CMakeFiles\exe0.dir\build.make:105: recipe for target 'exe0.exe' failed
mingw32-make[2]: *** [exe0.exe] Error 1
CMakeFiles\Makefile2:94: recipe for target 'CMakeFiles/exe0.dir/all' failed
mingw32-make[1]: *** [CMakeFiles/exe0.dir/all] Error 2
Makefile:102: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
这是我的 CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(SDL_Test_Project)
include_directories(include)
add_executable(exe0 main.cpp)
target_link_libraries(exe0 libSDL2main.a)
这里的 main.cpp 只是一个源文件。我已将SDL2.dll 和libSDL2main.a 放入项目目录的根目录。 (我使用 CMake GUI 在 Windows 10 中生成 Makefile)。
【问题讨论】:
-
试试
target_link_libraries(exe0 SDL2main SDL2)。
标签: c++ cmake mingw sdl-2 cmake-gui