Page 1 of 1

Can someone help me set up SFML?

Posted: August 10th, 2019, 5:01 pm
by TheCollector
Okay, so I followed this tutorial for the old SFML (https://www.youtube.com/watch?v=Z6alClFOGoM) and I'm having some trouble.
When I go to add additional dependencies under Input I don't know what file names to be putting in. There's two files for each one in the SFML/bin folder. For instance, there's sfml-graphics-2 and sfml-graphics-d-2. I've tried both and neither have made a difference with the error I'm receiving below. I've also tried what the guy using the old version of sfml was typing in (sfml-graphics-d) and that doesn't make a difference either.

Apparently I have the SFML-2.5.1 folder in the right spot (and I put copies of the sfml/bin files in the same spot in my project folder) because when I type #include "SFML" the SFML 2.5.1 folder pops up. But when I try to follow the rest of the tutorial by typing #include "SFML-2.5.1/Graphics.hpp" I get an error, cannot open the source file.

Anyone know what I'm doing wrong here?

I'm simply trying to load/display an image to the window.

Re: Can someone help me set up SFML?

Posted: August 10th, 2019, 5:26 pm
by TheCollector
I just found a video by the same guy I was watching earlier but for SFML 2.4. Going to try this too and see if anything helps get it going. Just to clarify, in the 'include directories' I updated the text from being the older version used in the video to SFML-2.5.1 and in 'additional library directories' put the same but with /lib after so it would reference the newer version of SFML which is what I have.

Re: Can someone help me set up SFML?

Posted: August 10th, 2019, 5:41 pm
by TheCollector
Okay, so it is still for example, sfml-graphics-d. I was looking in the wrong folder, the bin folder instead of the lib folder where they are all named -d. So I have the right names in now, still doesn't work though. In the new video he's typing it, #include <SFML/Graphics.hpp> and when I type in the first parts of that nothing comes up for SFML. SFML only comes up when I use quotations.

Re: Can someone help me set up SFML?

Posted: August 11th, 2019, 5:47 am
by albinopapa
Here's a bit of an explanation on #include syntax, at least as far as VS goes.

#include <filename.h> - means you have added some Include directory in the properties and you want the compiler to look through them first.

#include "filename.h> - means you have files in the project folder that need to be included and you want the compiler to look there.

So, if you have added SFML\Include to your project properties, then you should be able to use: #include <SFML\\Graphics.hpp>.

If you haven't added that folder to your project properties and instead just copied AND imported the files into visual studio, you must type: #include "SFML\\Graphics.hpp".

As for the .lib files, I'm still having issues with that one myself right now, but there are two ways to import them.

First: Add the SFML\lib folder to the directories page
Method 1:
Use the project properties page under Linker \ Input \ Additional Dependancies and add the .lib files to your project
Make sure you have the Configuration set for Release for the release versions and Debug for the debug versions
Release versions: sfml-system.lib, sfml-window.lib, sfml-graphics.lib
Debug versions: sfml-system-d.lib, sfml-window-d.lib, sfml-graphics-d.lib

Method 2:
Add some lines of code, #pragma comment, somewhere and the linker will use them to load the lib files.

Code: Select all

#if defined(NDEBUG) // Release build
#pragma comment( lib, "sfml-system.lib" )
#pragma comment( lib, "sfml-window.lib" )
#pragma comment( lib, "sfml-graphics.lib" )
#else  // Debug build
#pragma comment( lib, "sfml-system-d.lib" )
#pragma comment( lib, "sfml-window-d.lib" )
#pragma comment( lib, "sfml-graphics-d.lib" )
#endif
Hope this was helpful.

Re: Can someone help me set up SFML?

Posted: August 11th, 2019, 5:49 am
by albinopapa
Also, the only times I get the -2 at the end is on .dll files, but not the .lib files.

The .dll files are for runtime, when your program is actually running. The .lib files are used during compilation, to build your program. So you want to link to the .lib files when building/compiling.

Re: Can someone help me set up SFML?

Posted: August 13th, 2019, 5:44 pm
by TheCollector
It works!!! Thank you. That helped a lot.

Re: Can someone help me set up SFML?

Posted: August 25th, 2019, 8:34 pm
by DEM0N194
I would just like to point out that Chili did a couple SFML tutorials as well two of which are setting up SFML with package managers. I personally used the vcpkg method when I was messing around with SFML, it has the advantage of not having to mess with Visual Studio project settings and you can just include that shit in any project on your machine.

SFML Setup Using vcpkg with Visual Studio 2017/2015
SFML Setup Tutorial Visual Studio 2015 NuGet
SFML C++ Tutorial Basic Recipes [Animated Sprite]
SFML C++ Tutorial Intermediate Recipes [Shared Resource Management]

Re: Can someone help me set up SFML?

Posted: August 26th, 2019, 9:09 am
by albinopapa
For some reason or another I was never able to use vcpkg.

Re: Can someone help me set up SFML?

Posted: August 27th, 2019, 1:55 am
by Slidy
I've had troubles with vcpkg too, bit finicky and not always reliable, especially since the ports are all community maintained. Still, when it does work it's 👌

Re: Can someone help me set up SFML?

Posted: August 27th, 2019, 2:15 pm
by chili
I love vcpkg, but I've also been burned once now by a poorly maintained package. Props to Demon for the clutch links!