Can someone help me set up SFML?

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
TheCollector
Posts: 41
Joined: August 1st, 2019, 9:57 pm

Can someone help me set up SFML?

Post by TheCollector » August 10th, 2019, 5:01 pm

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.

TheCollector
Posts: 41
Joined: August 1st, 2019, 9:57 pm

Re: Can someone help me set up SFML?

Post by TheCollector » August 10th, 2019, 5:26 pm

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.

TheCollector
Posts: 41
Joined: August 1st, 2019, 9:57 pm

Re: Can someone help me set up SFML?

Post by TheCollector » August 10th, 2019, 5:41 pm

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.

albinopapa
Posts: 3801
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Can someone help me set up SFML?

Post by albinopapa » August 11th, 2019, 5:47 am

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.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 3801
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Can someone help me set up SFML?

Post by albinopapa » August 11th, 2019, 5:49 am

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.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

TheCollector
Posts: 41
Joined: August 1st, 2019, 9:57 pm

Re: Can someone help me set up SFML?

Post by TheCollector » August 13th, 2019, 5:44 pm

It works!!! Thank you. That helped a lot.

User avatar
DEM0N194
Posts: 28
Joined: April 15th, 2017, 4:14 pm
Location: Slovakia
Contact:

Re: Can someone help me set up SFML?

Post by DEM0N194 » August 25th, 2019, 8:34 pm

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]

albinopapa
Posts: 3801
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Can someone help me set up SFML?

Post by albinopapa » August 26th, 2019, 9:09 am

For some reason or another I was never able to use vcpkg.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Slidy
Posts: 34
Joined: September 9th, 2017, 1:19 pm

Re: Can someone help me set up SFML?

Post by Slidy » August 27th, 2019, 1:55 am

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 👌

User avatar
chili
Site Admin
Posts: 3841
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Can someone help me set up SFML?

Post by chili » August 27th, 2019, 2:15 pm

I love vcpkg, but I've also been burned once now by a poorly maintained package. Props to Demon for the clutch links!
Chili

Post Reply