'Is there a way to link SFML libraries in VSCode Mac?
Is there a reasonably easy to follow way to link SFML libraries with VSCode in macOS?
My case:
- Using Mac
- Using Clang with VSCode
- Have Xcode installed
- Am an amateur
Note : I am using clang and Mac
Solution 1:[1]
See my question and answer here: Manually link and compile C++ program with SFML (macOS)
In a nutshell:
- download sfml for mac
- copy include directory from extracted folder to your project directory
- copy the dynamic library files to your project also, folder lib
- in terminal type the g++ command and link to the dynamic libs
It will be something like this:
g++ main.cpp -o main -I include -L lib -l sfml-system -l sfml-window -l sfml-graphics -l sfml-audio -l sfml-network -Wl,-rpath ./lib
Solution 2:[2]
here's a boiler plate to link sfml in vs code:
Solution 3:[3]
If you have Macbook M1, the other answers won't work. The reason is because sfml from the website is compiled in x86_64, and you can't compile the libraries directly to arm64. So, you need sfml and pkg-config to be installed on Homebrew.
Command:
g++ main.cpp $(pkg-config --libs --cflags sfml-window sfml-system sfml-graphics) -o main
More detailed solution here: https://stackoverflow.com/a/53510642/16264548
If you don't wan to use pkg-config, then you can manually type in the locations:
main.cpp -I/opt/homebrew/Cellar/sfml/2.5.1_1/include -L/opt/homebrew/Cellar/sfml/2.5.1_1/lib -lsfml-window -lsfml-system -lsfml-graphics -o main
Solution 4:[4]
To enable the editor features, you can add library include files to C/C++ configurations:
- Open Command Palette (??P by default)
- Type and select "C/C++: Edit Configurations (UI)"
- In section "Include path" add a line:
/your/path/to/sfml/include/*
In my case, the path is /usr/local/Cellar/sfml/2.5.1_1/include/*
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | grybouilli |
| Solution 3 | |
| Solution 4 |
