Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

381
Views
How do I use SDL2 in my programs correctly?

I want to make a game using SDL2, but I'm unable to compile and/or run my code, please help!

SDL2 is notoriously hard to set up, and it's often the first library aspiring game developers try to use.

This post is intended as a canonical duplicate for common problems with setting up SDL2.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

On Mac this is what I follow for XCode (must install g++):

sdl linking:

g++ main.cpp -o main $(sdl2-config --cflags --libs)

XCODE project steps:

  1. open terminal app (macOS)

  2. BUILD SETTINGS (select 'all' and 'combined' search bar enter: "search")

  3. click on "header search paths(way right side click)

  4. add: /usr/local/include

  5. BUILD PHASES --> LINK BINARY LIBRARIES (click plus)

  6. type in SDL --> click "add other"

  7. press: command+SHIFT+g (to bring search bar)

  8. type in: usr/local/Cellar

  9. navigate to: SDL2 -->2.0.8 -->lib --> libSDL2-2.2.0.dylib (make sure not shortcut)

over 4 years ago · Santiago Trujillo Report

0

A solution for Visual Studio:

Why not use a package manager? I use vcpkg, and it makes super easy to consume 3rd party libraries. Grab the vcpkg source, and extract it to a safe place, like C:/, then run its bootstrap script bootstrap-vcpkg.bat, this will generate vcpkg executable. Then run vcpkg integrate install to make libraries installed with vcpkg available in Visual Studio.

Search for the library you need:

vcpkg search sdl

imgui[sdl2-binding]                   Make available SDL2 binding
libwebp[vwebp-sdl]                    Build the vwebp viewer tool.
magnum[sdl2application]               Sdl2Application library
sdl1                 1.2.15#12        Simple DirectMedia Layer is a cross-platform development library designed to p...
sdl1-net             1.2.8-3          Networking library for SDL
sdl2                 2.0.12-1         Simple DirectMedia Layer is a cross-platform 
...

Install it with: vcpkg install sdl2.

Now you just need include SDL2 headers, and everything will work out of the box. The library will be linked automatically.

You can learn more about vcpkg here.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!