Skip to content

Instantly share code, notes, and snippets.

@Mulperi
Last active January 9, 2024 00:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mulperi/e4816bec67fd813f3b63987202e81cd6 to your computer and use it in GitHub Desktop.
Save Mulperi/e4816bec67fd813f3b63987202e81cd6 to your computer and use it in GitHub Desktop.
SFML, Box2D in VSCode (macOS)

SFML, Box2D in VSCode (macOS)

Project structure

  • Create new project folder.
  • Inside of the project folder, create folders include and lib.
  • Create main.cpp with code:
  #include "include/SFML/Graphics.hpp"
  #include "include/box2d/box2d.h"
  int main(){}

Notice that since we have headers in the project folder /include, we need to use double quotes "" instead of <>.

  • Create compile.sh script with the following contents:
  #! /bin/sh
  g++ -std=c++11 main.cpp -o main -I include -L lib -l sfml-system -l sfml-window -l sfml-graphics -l sfml-audio -l sfml-network -l box2d -Wl,-rpath ./lib

Run this script after you placed sfml and box2d headers and library files into your project. It should compile and run without errors.

SFML

  • Download Mac version of SFML.
  • Copy contents of the include folder and paste them in your projects include folder (it should be project/include/SFML).
  • Copy contents of the lib folder (dylib files) and paste them in your projects lib folder.

Box2D

  • Download source code from Github: https://github.com/erincatto/box2d
  • Run box2d/build.sh
  • From box2d/build/bin folder there is now libbox2d.a. Copy and paste it to your projects lib folder.
  • Copy box2d/include/box2d folder and paste it to your projects include folder.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment