skip to Main Content

I have recently downloaded SDL2 and am trying to install it. I created a small test program consisting of a .cpp and a .h file.

I have put SDL2.frameworks inside of /Library/Frameworks and then made sure that it was added to General->Frameworks and Libraries and tried to #include <SDL2/SDL.h>. file not found.

I made sure to go to the build settings->Search Paths->Framework Search Paths to add /Library/Frameworks (it was already listed next to the setting but I readded it to the dropdown). I also added /Library/Frameworks/SDL2.framework to the Header Search Paths. file not found.

I tried to include <SDL2/SDL.h>, <SDL/SDL.h>, <SDL.h>, "SDL2/SDL.h", "SDL/SDL.h" and "SDL.h". none of these files were found.

2

Answers


  1. For the header search path, it should be set to FRAMEWORK_DIRCTORY/SDL2.framework/Headers/, or you can use FRAMEWORK_DIRCTORY/SDL2.framework and turn on recursive search.

    Then you should be able to use it with just #include <SDL.h>.


    Edit:

    After some investigation, seems like my original answer was more of a workaround. The proper way of including SDL library in your code should be using just #include <SDL2/SDL.h>, however it wasn’t working.

    The reason of that is when compiling the code, Xcode would attempt to copy the library to the product folder, so the compiled executable can have easy access to it. However, for some reason, Xcode copied the framework without the header folder (the reason is probably that Xcode is moving towards using Swift only, which doesn’t really have a "header" thing).

    By default, when you try to run the code, and it sees there is a SDL2.framework folder located in the product folder, it would use that framework, even if it doesn’t have the header folder located in it. But since it doesn’t actually have the header folder in it, it doesn’t actually run.


    To solve it, the easiest way is to remove it from the Targets/Build Phases/Embed Frameworks.

    By default when you add a framework to your project, it would also be added here. By removing it from the Embed Frameworks, it won’t copy the framework to product folder. And it will only attempt to search SDL framework from whatever you have put in the Build Settings/Framework Search Path.

    In the same time, you won’t need to have anything for Build Settings/Header Search Path, as it will look for Headers folders in your frameworks first.

    And with you code, you can just use #include <SDL2/SDL.h>.


    Even better, you can add the framework to Build Phases/Copy Files, and set the Destination to Frameworks, empty the Subpath, and potentially uncheck Copy only when installing, for better cross device usabilities.

    Login or Signup to reply.
  2. There’s something really strange about the SDL2_ttf framework. While this is NOT the "right" way to do it, I found everything was fine using the default XCode settings as long as #included the absolute path the header:

    #include "/Library/Frameworks/SDL2_ttf.framework/Headers/SDL_ttf.h"

    In my case, the library then worked fine.
    This may corroborate the idea of the header not getting copied into the local Frameworks directory.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search