SDL项目CMake构建失败

阿卡迪亚克

我尝试使用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;
}

这是日志输出。

[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

我究竟做错了什么?

埃姆莱

SDL_LIBRARY是错误的变量。您需要使用SDL2_LIBRARY

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

C ++项目构建失败

来自分类Dev

Gradle项目构建失败

来自分类Dev

在CMake中构建项目树

来自分类Dev

在CMake中构建项目树

来自分类Dev

在Xcode中项目构建失败

来自分类Dev

Ionic的Android项目构建失败

来自分类Dev

新建 Spring 项目构建失败

来自分类Dev

Xcode 10 - 构建项目失败

来自分类Dev

我的项目运行失败,说:“构建失败”

来自分类Dev

CMake中预期的构建失败测试

来自分类Dev

构建OpenCV(Ubuntu)时CMake失败

来自分类Dev

CMake生成的项目是否仅用于构建?

来自分类Dev

如何使用CMake构建DCMTK项目文件?

来自分类Dev

CMake:构建项目时执行C ++文件

来自分类Dev

SDL的ndk构建失败,找不到<iconv.h>

来自分类Dev

Gradle多项目构建失败,出现UnsupportedNotationException

来自分类Dev

Android项目构建失败:Java类重复

来自分类Dev

Azure-TFS部署项目使构建失败

来自分类Dev

Maven子项目构建失败

来自分类Dev

升级Unity版本后项目构建失败

来自分类Dev

FLUTTER项目错误:失败:构建失败,出现异常

来自分类Dev

OpenCV:在Windows 7上构建库期间,cmake失败

来自分类Dev

CMake一个用于多个项目的构建目录

来自分类Dev

如何使用CMake在项目中添加预构建的静态库?

来自分类Dev

如何自动添加CMake安装项目以构建配置

来自分类Dev

cmake,柯南和Qt Hello World项目构建错误

来自分类Dev

如何使用Cmake构建基于Qt远程对象的项目

来自分类Dev

osx cmake构建Qt5项目

来自分类Dev

XCode编译器错误,使用CMake构建的项目