Adding Xcode SDL2 Library (C++) Tutorial

23.03.2025
2.470
Adding Xcode SDL2 Library (C++) Tutorial

Writing Xcode for SDL2

I have prepared a tutorial article about Xcode SDL2. In this article, I will talk about how you can add and run the SDL2 framework in Xcode.

First we go to the SDL (Simple DirectMedia Layer) website to download SDL2.

SDL web page
SDL2 Download Page

We go to the download page by clicking onSDL 2.0″ in the“Download” section in the lower left corner or“Get the current stable SDL version 2.0.3” in the upper right corner.

sdl2.0.3 download page
SDL Install Notes

From here, we download the file to our computer by clicking the “SDL2-2.0.3.dmg (Intel 10.5+)” link from the“Development Binaries” section. Then we open the file by double-clicking it. After the file named SDL2 is displayed on our desktop in the /Volumes folder, we open it by double-clicking it.

SDL2 dmg
SDL2 Setup

The file named SDL2.framework in the folder:

“/ Applications/Xcode.app/Contents/ Developer/Platforms/ MacOSX.platform/Developer/ SDKs/MacOSX10.10.sdk/ System/Library/ Frameworks”
“~/Library/Frameworks”

paths.

Then we need to sign both files for the library to work. Otherwise the codes we wrote will not work. Click here for detailed information.

For Signing for Xcode SDL2, we open a terminal window and write the following codes:

1- sudo codesign -f -s – /Applications/Xcode.app /Contents/Developer/ Platforms/MacOSX.platform/ Developer/SDKs/ MacOSX10.10.sdk/System/ Library/Frameworks /SDL2.framework/SDL2

2- codesign -f -s – ~/Library/Frameworks/ SDL2.framework/SDL2

Now we can use the Xcode SDL2 library. You can write a test code and see if it works. To do this, start Xcode;

xcode sdl2
Xcode Create Project

Creating an Xcode Project

We say“Create a new Xcode project“. Then, as in the picture, we select“Command Line Tool” by saying OSX>Application from the template options on the left side to select the type of the project and click next:

xcode-template-selection
Xcode Project Named

In the second step we select the name of the project and the author and the language to be used(C++).

xcode-project-name
Xcode Choose File Path

Next, we choose where to save our project. You don’t need to create a folder for the project, Xcode itself will create a folder where your project files will be in with the project name you entered. After your project is ready, Xcode will open the“Build Settings” tab as below.

xcode-build-settings
Xcode SDL2 Buil Settings

From here we click on the“Build Phases” tab to add SDL2.framework to our project.

xcode-buildphases-tab.png
Xcode Build Phases

In this tab, click on the small arrow next to“Link Binary With Libraries” to expand it. What we will do here is to link the library with the binary. For this, we open the following window by clicking on the(+) plus icon in the lower left corner.

link-binary-xcode
SDL2 Lib Add

We find the library named SDL2.framework, which we added as a framework in the first part of the article, from this list and click the“Add” button.

Now we can write a test code in the main.cpp file, as you can see in the window below, to internalize the library we write“#include <SDL2/SDL.h>“, that is, we write a foreslash after the name of the library and the name of the header we want to use.

xcode-SDL2-testcode
Xcode Header Row

To run the code you can press the play button in the top left corner or Product>Run or compile and build with the(⌘+R) key combination.

MAKE A COMMENT
COMMENTS - 0 COMMENTS

No comments yet.

Bu web sitesi, bilgisayarınıza bilgi depolamak amacıyla bazı tanımlama bilgilerini kullanabilir.
Bu bilgilerin bir kısmı sitenin çalışmasında esas rolü üstlenirken bir kısmı ise kullanıcı deneyimlerinin iyileştirilmesine ve geliştirilmesine yardımcı olur.
Sitemize ilk girişinizde vermiş olduğunuz çerez onayı ile bu tanımlama bilgilerinin yerleştirilmesine izin vermiş olursunuz.
Çerez bilgilerinizi güncellemek için ekranın sol alt köşesinde bulunan mavi kurabiye logosuna tıklamanız yeterli. Kişisel Verilerin Korunması,
Gizlilik Politikası ve Çerez (Cookie) Kullanımı İlkeleri hakkında detaylı bilgi için KVKK&GDPR sayfamızı inceleyiniz.
| omersahin.com.tr |
Copyright | 2007-2025