CMake没有链接SDL库?

时间:2015-10-11 06:25:43

标签: c++ command-line cmake sdl

我第一次尝试CMake。当我从命令行运行cmake时,一切似乎都没问题:

alex@mileena:~/Projects/SDLTutorial/_build$ cmake ..
-- Configuring done
-- Generating done
-- Build files have been written to: /home/alex/Projects/SDLTutorial/_build

但是当我运行make时,我得到了对所有SDL函数的未定义引用。我已经加入了SDL.h。

alex@mileena:~/Projects/SDLTutorial/_build$ make                  
Linking CXX executable SDLTutorial
CMakeFiles/SDLTutorial.dir/main.cpp.o: In function `main':
main.cpp:(.text+0x15): undefined reference to `SDL_Init'
main.cpp:(.text+0x43): undefined reference to `SDL_CreateWindow'
main.cpp:(.text+0x6f): undefined reference to `SDL_CreateRenderer'
main.cpp:(.text+0xa3): undefined reference to `SDL_SetRenderDrawColor'
main.cpp:(.text+0xb2): undefined reference to `SDL_RenderClear'
main.cpp:(.text+0xc1): undefined reference to `SDL_RenderPresent'
main.cpp:(.text+0xcb): undefined reference to `SDL_Delay'
main.cpp:(.text+0xd0): undefined reference to `SDL_Quit'
collect2: error: ld returned 1 exit status
CMakeFiles/SDLTutorial.dir/build.make:85: recipe for target 'SDLTutorial' failed
make[2]: *** [SDLTutorial] Error 1

这些是CMakeLists.txt的内容。我是否正确地包括了图书馆?

cmake_minimum_required(VERSION 2.8)
project(SDLTutorial)
add_executable(SDLTutorial main.cpp)
find_library(SDL REQUIRED)
if (SDL_FOUND)
    include_directories(${SDL_INCLUDE_DIR})
    target_link_libraries(SDLTutorial ${SDL_LIBRARY})
endif (SDL_FOUND)
install(TARGETS SDLTutorial DESTINATION bin) 

0 个答案:

没有答案