user14686569
user14686569

Reputation:

SDL2 installing on xCode

I have downloaded SDL2.frameworks from https://www.libsdl.org and installed it into /Libraries/Frameworks/. Then I have pointed xcode a path of frameworks and headers in 'Build Settings', in 'General' 'Frameworks and Libraries' pointed at framework file libSDL2-2.0.0.dylib . The I type #include <SDL2/SDL.h> and try to build the project. It shows 150+ warnings, but if I try to Run the program it says that Library not loaded. Why? what is the problem? I'm using Big Sur OS picture1 build settings general

Upvotes: 3

Views: 2401

Answers (3)

Egel
Egel

Reputation: 1956

I recently had same problem as the author @user14686569, although on newer version macOS Ventura. Due to few changes that happened to system paths, which also affected brew, I enhanced the author's with few simple tweeks to be more up to date for building projects with SDL2 library, and even more.

  1. install sdl2 via brew

    brew install sdl2
    
  2. in Xcode, go to your Project's setting into section Build Settings > Search Paths, like on screenshot.

    • add to section "Header Search Paths" -> /opt/homebrew/include
    • add to section "Library Search Paths" -> /opt/homebrew/lib

    Project's Settings > Build Settings > Search Paths

  3. All set. Now, you should be able to find all libraries installed via brew, like following SDL2.

    Project successful compilation

Upvotes: 0

Anony
Anony

Reputation: 11

You need to codesign the Framework.(The command by the Lazy Foo may be not right).

  1. Find out one's own signature:
security find-identity
  1. Sign the frameworks:
codesign -f -s "XXXX Your signature" SDL2.framework

Don't forget to sign the another hidapi.framework within the ./Versions/A/Frameworks.

  1. You can verify the signature:
codesign -display --verbose=4 SDL2.framework

Upvotes: 1

user14686569
user14686569

Reputation:

I have figured it out.

  1. I have installed homebrew from https://brew.sh
  2. I typed in terminal brew install sdl2
  3. Then I have showed the path of framework (in xCode select project file >> build settings >> header search paths) and using cmd+shift+g type /usr/local/include
  4. In General Frameworks & Libraries put libSDL2-2.0.0.dylib (its here /usr/local/Cellar/sdl2/2.0.14_1/lib)
  5. And most important I have checked Disable Library Validations in Signing & Capabilities

After these steps code started to work for me

Upvotes: 2

Related Questions