• <bdo id='yy2yI'></bdo><ul id='yy2yI'></ul>
        <tfoot id='yy2yI'></tfoot>

        <legend id='yy2yI'><style id='yy2yI'><dir id='yy2yI'><q id='yy2yI'></q></dir></style></legend>
      1. <i id='yy2yI'><tr id='yy2yI'><dt id='yy2yI'><q id='yy2yI'><span id='yy2yI'><b id='yy2yI'><form id='yy2yI'><ins id='yy2yI'></ins><ul id='yy2yI'></ul><sub id='yy2yI'></sub></form><legend id='yy2yI'></legend><bdo id='yy2yI'><pre id='yy2yI'><center id='yy2yI'></center></pre></bdo></b><th id='yy2yI'></th></span></q></dt></tr></i><div id='yy2yI'><tfoot id='yy2yI'></tfoot><dl id='yy2yI'><fieldset id='yy2yI'></fieldset></dl></div>

        <small id='yy2yI'></small><noframes id='yy2yI'>

        如何在 cmake 中使用 SDL2 和 SDL_image

        时间:2023-08-28
          1. <small id='dHF0s'></small><noframes id='dHF0s'>

            <tfoot id='dHF0s'></tfoot>
          2. <legend id='dHF0s'><style id='dHF0s'><dir id='dHF0s'><q id='dHF0s'></q></dir></style></legend>

                  <tbody id='dHF0s'></tbody>
                • <bdo id='dHF0s'></bdo><ul id='dHF0s'></ul>
                  <i id='dHF0s'><tr id='dHF0s'><dt id='dHF0s'><q id='dHF0s'><span id='dHF0s'><b id='dHF0s'><form id='dHF0s'><ins id='dHF0s'></ins><ul id='dHF0s'></ul><sub id='dHF0s'></sub></form><legend id='dHF0s'></legend><bdo id='dHF0s'><pre id='dHF0s'><center id='dHF0s'></center></pre></bdo></b><th id='dHF0s'></th></span></q></dt></tr></i><div id='dHF0s'><tfoot id='dHF0s'></tfoot><dl id='dHF0s'><fieldset id='dHF0s'></fieldset></dl></div>
                  本文介绍了如何在 cmake 中使用 SDL2 和 SDL_image的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在寻找使用 SDL2SDL_image 和 cmake 编译 c++ 程序的最简单方法.

                  I'm looking for the simplest way to compile a c++ program using SDL2 and SDL_image with cmake.

                  经过数小时的搜索,这是我的最佳尝试:

                  Here is my best attempt, after hours of searching:

                  CMakeLists.txt

                  project(shooter-cmake2)
                  
                  cmake_minimum_required(VERSION 2.8)
                  
                  set(SOURCES
                  shooter.cpp
                  classes.cpp
                  utils.cpp
                  )
                  
                  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
                  
                  add_executable(${PROJECT_NAME} ${SOURCES})
                  
                  INCLUDE(FindPkgConfig)
                  PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
                  PKG_SEARCH_MODULE(SDL2_image REQUIRED sdl2_image)
                  INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIRS} ${SDL2IMAGE_INCLUDE_DIR})
                  TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${SDL2_LIBRARIES} ${SDL2IMAGE_LIBRARY})
                  

                  我收到这些错误:

                  In function `loadTexture(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, SDL_Renderer*)':
                  undefined reference to `IMG_LoadTexture'
                  collect2: ld returned 1 exit status
                  

                  这是函数调用:

                  #include "SDL.h"
                  #include "SDL_image.h"
                  
                  SDL_Texture* loadTexture(const std::string &file, SDL_Renderer *ren){
                      SDL_Texture *texture = IMG_LoadTexture(ren, file.c_str());
                      texture != nullptr or die("LoadTexture");
                      return texture;
                  }
                  

                  我很绝望.请帮我!谢谢!:)

                  I am desperate. Please help me! Thanks! :)

                  推荐答案

                  我认为以下方法会起作用,因为它会在我的 ubuntu 系统上找到库,并且您提供的示例函数可以链接:

                  I think that the following will work, as it finds the libraries on my ubuntu system and the example function you provided can link:

                  project(shooter-cmake2)
                  
                  cmake_minimum_required(VERSION 2.8)
                  
                  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
                  
                  add_executable(${PROJECT_NAME} src/test.cpp)
                  
                  INCLUDE(FindPkgConfig)
                  
                  PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
                  PKG_SEARCH_MODULE(SDL2IMAGE REQUIRED SDL2_image>=2.0.0)
                  
                  INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIRS} ${SDL2IMAGE_INCLUDE_DIRS})
                  TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${SDL2_LIBRARIES} ${SDL2IMAGE_LIBRARIES})
                  

                  如果使用 --debug-output 执行 cmake,它会输出:

                  If cmake is executed with --debug-output it outputs:

                  -- Found PkgConfig: /usr/bin/pkg-config (found version "0.26") 
                  Called from: [2]    /usr/share/cmake-2.8/Modules/FindPkgConfig.cmake
                              [1] $USER/stack-overflow/cmake-sdl2-image/CMakeLists.txt
                  -- checking for one of the modules 'sdl2'
                  Called from: [1]    $USER/stack-overflow/cmake-sdl2-image/CMakeLists.txt
                  -- checking for one of the modules 'SDL2_image>=2.0.0'
                  Called from: [1]    $USER/stack-overflow/cmake-sdl2-image/CMakeLists.txt
                  

                  这让我检查了

                  /usr/lib/x86_64-linux-gnu/pkgconfig/sdl2.pc
                  /usr/lib/x86_64-linux-gnu/pkgconfig/SDL2_image.pc
                  

                  我注意到 SDL2_image.pc 包含名称:SDL2_image我认为应该将第三个参数与此库的 PKG_SEARCH_MODULE 匹配.

                  I noticed that SDL2_image.pc contains Name: SDL2_image which I assumed should match the third parameter to PKG_SEARCH_MODULE for this library.

                  这篇关于如何在 cmake 中使用 SDL2 和 SDL_image的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 C++ 源代码中读取 CMake 变量 下一篇:扩展 setuptools 扩展以在 setup.py 中使用 CMake?

                  相关文章

                    • <bdo id='843A0'></bdo><ul id='843A0'></ul>

                  1. <legend id='843A0'><style id='843A0'><dir id='843A0'><q id='843A0'></q></dir></style></legend>

                  2. <small id='843A0'></small><noframes id='843A0'>

                    1. <tfoot id='843A0'></tfoot>
                      <i id='843A0'><tr id='843A0'><dt id='843A0'><q id='843A0'><span id='843A0'><b id='843A0'><form id='843A0'><ins id='843A0'></ins><ul id='843A0'></ul><sub id='843A0'></sub></form><legend id='843A0'></legend><bdo id='843A0'><pre id='843A0'><center id='843A0'></center></pre></bdo></b><th id='843A0'></th></span></q></dt></tr></i><div id='843A0'><tfoot id='843A0'></tfoot><dl id='843A0'><fieldset id='843A0'></fieldset></dl></div>