This Q&A post comes from lots and lots of questions related to sfml library when people try to configure manually their VS projects. Sometimes answers aren't complete or they're too specific.
I would like to compile in a single post how to configure VS to be able to use the SFML library both statically and dynamically.
So:
1. How can I configure my VS project with sfml libraries dynamically, in a general way?
2. How can I configure my VS project with sfml libraries statically, in a general way?
First, I recommend carefully follow the SFML tutorial about configuring the library in Visual Studio, if something goes wrong, then check this answer.
I will divide this answer in two groups, how to configure sfml as a dynamic library and how to do it as a static library.
Common steps
Let's create a VS project (I will use VS2013 and SFML 2.5.1, but it's pretty much the same with other versions). Create it as ConsoleApplication and check Empty Project.
Download sfml libraries, latest stable version preferably, selecting your corresponding system (in my case Visual C++ 12 (2013) - 64-bit). Extract this file where your
.vcxproj
file is. This will create a folder named SFML-X.X.X depending on your version.Download the external libraries, in my case 64 bits version. Create a folder called extlib inside the library folder and place this external libraries there.
Create a
main.cpp
file, and paste the example code from SFML tutorials.SFML As Dynamic Library
Go to Build->Configuration Manager. If you are using a 64 bits library, first you should create a new Solution Platform. Click on Active Solutions Platform->New, select x64 copying from Win32 configuration. I prefer to uncheck Create new project platforms.
Create Debug-Dynamic and Release-Dynamic compilation profiles. With your active solution platform selected, click on Configuration (of the project) and New. You can call it Debug-Dynamic and copy it from Debug configuration (also, uncheck Create new...). Repeat creating a Release-Dynamic configuration.
Open Project Properties->Debugging. Select Debug-Dynamic configuration and modify field Environment with this value
PATH=$(ProjectDir)\SFML-2.5.1\bin;%PATH%
. This will indicate VS where.dll
libraries can be found.Over C/C++ section, modify Additional include directories field by adding this path
$(ProjectDir)\SFML-2.5.1\include
. This will indicate VS where.hpp
files are located.On Linker section, modify Additional library directories field by adding this path
$(ProjectDir)\SFML-2.5.1\lib
. This will indicate VS where.lib
files can be found.Finally, on Linker->Input, modify Additional dependencies field by adding all
.lib
files needed:Note
-d
suffix to indicate debug libraries-d
suffix, because they're release librariesSFML As Static Library
Go to Build->Configuration Manager. Create Debug-Static and Release-Static compilation profiles. With your active solution platform selected, click on Configuration (of the project) and New. You can call it Debug-Static and copy it from Debug configuration (also, uncheck Create new...). Repeat creating a Release-Static configuration.
Open Project Properties and select Debug-Static configuration. Over C/C++ section, modify Additional include directories field by adding this path
$(ProjectDir)\SFML-2.5.1\include
. This will indicate VS where.hpp
files are located.On C/C++ section->Preprocessor*, modify Preprocessor definitions field by adding
SFML_STATIC
definition. This will indicate preprocessor that SFML will be statically compiled.Over Linker section, modify Additional library directories field by adding this paths
$(ProjectDir)\SFML-2.5.1\extlib;$(ProjectDir)\SFML-2.5.1\lib;
. This will indicate VS where.lib
files from external sources and from SFML can be found.Finally, on Linker->Input section, modify Additional dependencies field with all
.lib
files needed:Note
-d
suffix to indicate debug librariesNote2
-s
suffix to indicate static libraries-d
suffix, because they're release libraries, but they'll keep-s
suffix.