简体   繁体   English

在OSX 10.11上使用SDL2和SDL2_image(在CLion 1.1中使用CMake 3.3)

[英]Using SDL2 with SDL2_image on OSX 10.11 (CMake 3.3 within CLion 1.1)

I'm following a couple of tutorials from reddit.com/r/limeoats to learn some game development in c++. 我正在关注reddit.com/r/limeoats的一些教程,以学习c ++中的一些游戏开发。 I'm not experienced with CMake or CLion and have managed to google my way this far. 我对CMake或CLion没有经验,并设法以我的方式google。

I had everything working up until I updated OSX to El Capitan (10.11). 在将OSX更新到El Capitan(10.11)之前,我已经做好了一切准备工作。 It seems that I can no longer use #include "SDL2/SDL.h" but instead need to use #include "SDL.h" Then it can find the SDL headers. 似乎我不能再使用#include "SDL2/SDL.h" ,而是需要使用#include "SDL.h"然后它就可以找到SDL头。 The problem comes in when I also use #include "SDL_image.h" I get the following compiler error: 当我也使用#include "SDL_image.h"我得到以下编译器错误:

/Library/Frameworks/SDL2_image.framework/Headers/SDL_image.h:27:10:
fatal error: 'SDL2/SDL.h' file not found
#include <SDL2/SDL.h>
         ^

Looking into the header file in my Frameworks folder, it has #include <SDL2/SDL.h> but CMake is providing it as SDL.h for some reason after upgrading OSX to 10.11. 查看我的Frameworks文件夹中的头文件,它有#include <SDL2/SDL.h>但是在将OSX升级到10.11之后,CMake因某种原因将其作为SDL.h提供。

How do I get the SDL extensions to play nice with the updated header path? 如何使SDL扩展与更新的标头路径一起使用? Or how do I get CMake to give me the old SDL2/SDL.h header path back? 或者我如何让CMake给我旧的SDL2 / SDL.h标头路径?

Below is my CMakeLists.txt and I got the FindSDL2.cmake (note the comment on line 50) and FindSDL2_image.cmake from here . 下面是我的CMakeLists.txt,我从这里得到了FindSDL2.cmake (注意第50行的注释)和FindSDL2_image.cmake。

cmake_minimum_required(VERSION 3.3)
project(Cavestory)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)

include_directories(${PROJECT_SOURCE_DIR}/source/headers)

find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED >=2.0.0)

include_directories(${SDL2_INCLUDE_DIR})
include_directories(${SDL2_IMAGE_INCLUDE_DIR})

file(GLOB SOURCE_FILES "source/src/*.cpp")

add_executable(Cavestory ${SOURCE_FILES})

# One thread said this is all I should need to link SDL2
# but cannot get this to work at all
#target_link_libraries(Cavestory SDL2 SDL2_image)

#add_custom_command(TARGET Cavestory POST_BUILD
#        COMMAND ${CMAKE_COMMAND} -E copy_directory
#        ${CMAKE_SOURCE_DIR}/content $<TARGET_FILE_DIR:Cavestory>)

And my directory structure (if it helps)... 和我的目录结构(如果有帮助)......

/Cavestory (root)
    CMakeLists.txt
    /bin
    /cmake
        FindSDL2.cmake
        FindSDL2_image.cmake
    /content
        /sprites
            **images**
    /docs
    /source
        /headers
           **header files**
        /src
           **code files**

I feel stupid... My CMakeLists.txt file is correct except i needed to add the following 我觉得愚蠢...我的CMakeLists.txt文件是正确的,除了我需要添加以下内容

target_link_libraries(Cavestory ${SDL2_LIBRARY} ${SDL2_IMAGE_LIBRARY})

instead of 代替

target_link_libraries(Cavestory SDL2 SDL2_image)

This fixes the SDL linking issue from SDL_image.h; 这修复了SDL_image.h中的SDL链接问题; However, after updating to El Capitan, I can no longer reference SDL via #include "SDL2/SDL.h" and must use #include "SDL.h" -- while this is preferred, I'd like to know why/how this changed between OSX 10.10 and OSX 10.11. 但是,在更新到El Capitan后,我不能再通过#include "SDL2/SDL.h"引用SDL并且必须使用#include "SDL.h" - 虽然这是首选,但我想知道为什么/如何这在OSX 10.10和OSX 10.11之间发生了变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM