使用CMake设置SDL2时,“对“ WinMain @ 16”的未定义引用”

时间:2019-05-24 18:46:02

标签: cmake sdl-2 clion

因此,我想学习如何使用CMake(特别是在CLion中),现在我正在尝试使用它来设置SDL2。我的Modules文件夹中有FindSDL2.cmake,这是我的代码:

CMakeLists.txt:

cmake_minimum_required(VERSION 3.13)
project(CLion_Tests)

set(CMAKE_CXX_STANDARD 11)

set(SDL2_PATH "C:/Users/Lerchi/Downloads/SDL/SDL2main/64")
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})

add_executable(CLion_Tests main.cpp)
target_link_libraries(CLion_Tests ${SDL2_LIBRARY})

和main.cpp就是这样:

#include <iostream>
#include <SDL.h>

int main(int argc, char* args[]) {
    SDL_Init(SDL_INIT_EVERYTHING);
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

我得到的错误是

CMakeFiles\CLion_Tests.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x1c): undefined reference to `SDL_Init'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [CLion_Tests.exe] Error 1
CMakeFiles\CLion_Tests.dir\build.make:87: recipe for target 'CLion_Tests.exe' failed
mingw32-make.exe[1]: *** [CMakeFiles/CLion_Tests.dir/all] Error 2
CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/CLion_Tests.dir/all' failed
mingw32-make.exe: *** [all] Error 2
Makefile:82: recipe for target 'all' failed

0 个答案:

没有答案