Quick Answer
g++ -c main.cpp -IC:\SFML-2.1\include -DSFML_STATIC
g++ main.o -o main -LC:\SFML-2.1\lib -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32
main
Long Answer
I'll show you how to either link the project statically or dynamically. It doesn't matter which one you chose to do if you are running the project on your computer, but if you want to send the executable file to another device, choose static linking.
Compile Project
First, compile, but not link, your project using the -c
flag. Make sure to include the SFML header files using the -I
prefix.
If you are going to statically link SFML, include SFML_STATIC
using the -D
flag.
// dynamic linking
g++ -c main.cpp -IC:\SFML-2.1\include
// static linking
g++ -c main.cpp -IC:\SFML-2.1\include -DSFML_STATIC
Link Project
Now you have to link the SFML libraries. To link a library, use the -l
prefix. For convenience, link the ones you're most likely to use: -lsfml-graphics
, -lsfml-window
, and -ssfml-system
.
If you are statically linking, use a -s
prefix on the libraries: -lsfml-graphics-s
, -lsfml-window-s
, and -lsfml-system-s
.
You also have to link certain dependencies for the libraries. That's the opengl32
, winmm
, and gdi32
libraries. Again, use the prefix -l
to link the libraries (you don't need the -s
suffix on these libraries even if you are statically linking it).
// dynamic linking
g++ main.o -o main -LC:\SFML-2.1\lib -lsfml-graphics -lsfml-window -lsfml-system -lopengl32 -lwinmm -lgdi32
// static linking
g++ main.o -o main -LC:\SFML-2.1\lib -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32
Run Project
And lastly, just type the name of the executable file in the command line:
main
And you're done!