C++ SDL项目CMake生成失败

C++ SDL项目CMake生成失败,c++,build,cmake,sdl,C++,Build,Cmake,Sdl,我尝试使用CMake设置SDL项目,但似乎可执行文件链接不正确 这是我使用的CMakeLists.txt cmake_minimum_required(VERSION 3.0) project(MuspellsheimR) # includes cmake/FindSDL2.cmake set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules) # find SDL2 find_package(SDL2 REQUIRED) inclu

我尝试使用CMake设置SDL项目,但似乎可执行文件链接不正确

这是我使用的CMakeLists.txt

cmake_minimum_required(VERSION 3.0)
project(MuspellsheimR)

# includes cmake/FindSDL2.cmake
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)

# find SDL2
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})

set(SOURCE_FILES src/main.cpp)

add_executable(MuspellsheimR ${SOURCE_FILES})
target_link_libraries(MuspellsheimR ${SDL_LIBRARY})
src/main.cpp
如下所示:

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

int main(int, char**){
    if (SDL_Init(SDL_INIT_VIDEO) != 0){
        std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl;
        return 1;
    }
    SDL_Quit();
    return 0;
}

我做错了什么?

SDL\U库是错误的变量。你需要使用
SDL2\u库

Awww,当然,你是对的,我真是太傻了。谢谢
[omtcyf0@localhost MuspellsheimR_Build]$ cmake -G "Unix Makefiles" ../MuspellsheimR
-- The C compiler identification is GNU 5.1.1
-- The CXX compiler identification is GNU 5.1.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found SDL2: /usr/local/lib/libSDL2main.a;/usr/local/lib/libSDL2.so;-lpthread  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/omtcyf0/Desktop/MuspellsheimR_Build
[omtcyf0@localhost MuspellsheimR_Build]$ 
[omtcyf0@localhost MuspellsheimR_Build]$ ls
CMakeCache.txt  CMakeFiles  cmake_install.cmake  Makefile
[omtcyf0@localhost MuspellsheimR_Build]$ make
Scanning dependencies of target MuspellsheimR
[100%] Building CXX object CMakeFiles/MuspellsheimR.dir/src/main.cpp.o
Linking CXX executable MuspellsheimR
CMakeFiles/MuspellsheimR.dir/src/main.cpp.o: In function `main':
main.cpp:(.text+0x25): undefined reference to `SDL_Init'
main.cpp:(.text+0x3e): undefined reference to `SDL_SetVideoMode'
main.cpp:(.text+0x51): undefined reference to `SDL_RWFromFile'
main.cpp:(.text+0x5e): undefined reference to `SDL_LoadBMP_RW'
main.cpp:(.text+0x7c): undefined reference to `SDL_UpperBlit'
main.cpp:(.text+0x88): undefined reference to `SDL_Flip'
main.cpp:(.text+0x92): undefined reference to `SDL_Delay'
main.cpp:(.text+0x9e): undefined reference to `SDL_FreeSurface'
main.cpp:(.text+0xa3): undefined reference to `SDL_Quit'
collect2: error: ld returned 1 exit status
CMakeFiles/MuspellsheimR.dir/build.make:85: recipe for target 'MuspellsheimR' failed
make[2]: *** [MuspellsheimR] Error 1
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/MuspellsheimR.dir/all' failed
make[1]: *** [CMakeFiles/MuspellsheimR.dir/all] Error 2
Makefile:116: recipe for target 'all' failed
make: *** [all] Error 2