Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Can't get SFML on VS 2022  (Read 837 times)

0 Members and 1 Guest are viewing this topic.

bobojoeho

  • Newbie
  • *
  • Posts: 11
    • View Profile
Can't get SFML on VS 2022
« on: February 07, 2024, 01:40:42 am »
So I am trying to get SFML, and I want to get into C++ coding.  I am very new to this.  I followed this tutorial: https://www.sfml-dev.org/tutorials/2.6/start-vc.php, after installing SFML C++ 17 32 bit.  I am using Visual Studio 2022 with C++ 17.  I added to my properties what the pictures in the tutorial said, but now every time I try to include the sfml library or do anything it says: Error C1083 Cannot open include file: 'SFML/Graphics.hpp': No such file or directory Project C:\Users\xxxxx\source\repos\Project\sfmlproject\Source.cpp.  I have no idea what is wrong please help me.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
Re: Can't get SFML on VS 2022
« Reply #1 on: February 07, 2024, 08:48:42 am »
Make sure to not just follow the pictures, but also what's written in the tutorial.

Personally, I can very much recommend using the CMake Template Project, as it will setup and link SFML automatically and you don't have to fiddle with IDE configurations.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3360
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Can't get SFML on VS 2022
« Reply #2 on: February 07, 2024, 05:13:34 pm »
Remember that those properties are "per project" and have to set each time so if you've start a new project since setting the properties, you'll need to set them again.

For your issue, I'd be checking the headers/include directory to make sure they are where you told VS they are (in your project properties).

Note that you if you set these properties for one configuration (release, for example) then they won't be set for the other (debug, for example). You can set multiple configurations at once but remember that some properties need to be set differently for each configuration.

Are you using double-quotes or angle brackets for your inclusion?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

bobojoeho

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Can't get SFML on VS 2022
« Reply #3 on: February 08, 2024, 12:47:38 am »
I tried quotes around the include at the beginning, still doesn't work.  I will tell you what I have done from the start and if you wouldn't mind trying to see if I did something wrong then that would be amazing.  First, I downloaded SFML C++ 17 32 bits.  I unzipped the folder, but left it in downloads.  I went into a blank, fresh project on Visual Studio 2022.  Btw my language is C++ 17.  I went into project properties, then into configuration properties, then into C/C++, then into general.  I made sure to set configuration to all configurations, and platform to Active(x64).  Under Additional Include Directories, I put C:\users\xxxxxx\Downloads\SFML-2.6.1-windows-vc17-32-bit\SFML-2.6.1\include\SFML.  Then I went into Linker/General, and under Additional Library Directives I put C:\users\xxxxxx\Downloads\SFML-2.6.1-windows-vc17-32-bit\SFML-2.6.1\lib.  After that I went into Linker\Input and under additional dependencies, before all the rest of the stuff, I inserted sfml-graphics.lib;sfml-window.lib;sfml-system.lib;.

Sry bout the big chunk of text but if you see anything I did wrong please tell me.

bobojoeho

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Can't get SFML on VS 2022
« Reply #4 on: February 08, 2024, 01:14:30 am »
Ok guys nvm I figured that part out.  My directory was wrong, and apparently SFML was expecting to be ran in x86 so I changed to that.  Now I need to copy my SFML DLL files "to the directory where your compiled executable is" -the tutorial page I originally mentioned.

Probably a dumb question but where can I find my compiled executable?
I just need to copy my DLL's there and I think everything should work.

kojack

  • Sr. Member
  • ****
  • Posts: 327
  • C++/C# game dev teacher.
    • View Profile
Re: Can't get SFML on VS 2022
« Reply #5 on: February 08, 2024, 02:06:14 am »
Mixing the 32bit SFML download with 64bit platform in the project settings isn't going to work, but that's not the cause of the issue here. (you can't mix 32bit and 64bit).

The error in the first post says it can't find SFML/Graphics.hpp. So the code most likely has:
#include <SFML/Graphics.hpp>

But your settings have the additional includes set to: C:\users\xxxxxx\Downloads\SFML-2.6.1-windows-vc17-32-bit\SFML-2.6.1\include\SFML
Visual Studio adds the #include path to the additional includes path, so it was looking for:
C:\users\xxxxxx\Downloads\SFML-2.6.1-windows-vc17-32-bit\SFML-2.6.1\include\SFML\SFML\Graphics.hpp
(double SFML).

If you change the additional includes to: C:\users\xxxxxx\Downloads\SFML-2.6.1-windows-vc17-32-bit\SFML-2.6.1\include it should work.

(Or so both #include <Graphics.hpp> and #include <SFML/Graphics.hpp> work, you can set the additional includes path to: C:\users\xxxxxx\Downloads\SFML-2.6.1-windows-vc17-32-bit\SFML-2.6.1\include;C:\users\xxxxxx\Downloads\SFML-2.6.1-windows-vc17-32-bit\SFML-2.6.1\include\SFML )

bobojoeho

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Can't get SFML on VS 2022
« Reply #6 on: February 08, 2024, 03:27:14 am »
Ok so I changed my include paths and it still doesn't work.  The program will compile successfully with 0 errors, but my script (obtained from end of tutorial) doesn't work.  It will open up a window, but immediately give an error message saying that sfml-window-2.dll wasn't found.

As for the 32bit SFML not being compatible with 64bit VS, would you suggest running my VS in Win32 or installing 64bit SFML?

kojack

  • Sr. Member
  • ****
  • Posts: 327
  • C++/C# game dev teacher.
    • View Profile
Re: Can't get SFML on VS 2022
« Reply #7 on: February 08, 2024, 03:48:37 am »
The include paths thing was for the compile error from the top.

Visual studio can build Windows executables (exe) and libraries (dlls) as either 32bit or 64bit. The important part is that they can't be mixed. The executable and all libraries must be the same bit size or they are incompatible. So you should get the SFML that matches what you want your project to be.

Windows itself used to have 32bit and 64bit versions. The 32bit Windows can only run 32bit programs. The 64bit Windows can run both 32bit and 64bit programs.

My personal preference is 64bit, I stopped doing anything C++ related in 32bit many years ago (some of my stuff uses a lot of ram). But 32bit does have a wider audience (some people still using old 32bit versions of windows).

bobojoeho

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Can't get SFML on VS 2022
« Reply #8 on: February 08, 2024, 05:02:42 am »
So the problem isn't with my bit sizes?  Since Visual Studio can work with both, and I have the lower bit version of SFML?

Well if that's true, then I still need to fix sfml-window-2.dll not being found.

The tutorial said if I am using the dynamic version (which I am), then I need to copy my DLL files "to the directory where your compiled executable is"

Apologies again for my lack of knowledge, I am pretty new to this.

kojack

  • Sr. Member
  • ****
  • Posts: 327
  • C++/C# game dev teacher.
    • View Profile
Re: Can't get SFML on VS 2022
« Reply #9 on: February 08, 2024, 05:23:07 am »
Don't worry, it does get pretty confusing at the beginning. Visual Studio doesn't go out of its way to make it easier either (as we'll see soon).

SFML 32bit will be fine, as long as your project has the platform set to Win32/X86 instead of X64.

For the missing DLLs...
When the run a program, it looks in a few places for the dlls. One is the system path (set in Windows, every directory in the path will be searched). The other is the "working directory".
If you run a program by clicking on it in explorer, the working directory is set to the same directory as where the program is. So if you click on c:\game\main.exe, it will search c:\game for the dlls.

This is where VS is annoying.
Running a program from inside of Visual Studio uses a working directory set in the project properties. The default is $(ProjectDir), which means it will look for the dlls in the same directory as the .vcxproj file, not where the exe ended up!
I always change the working directory to $(TargetDir), that makes it look for dlls where the exe is.

The setting is in Debugging / Working Directory. If you set it to $(TargetDir) and copy the SFML dlls into the same directory as the exe file you built, it should hopefully work.

Hapax

  • Hero Member
  • *****
  • Posts: 3360
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Can't get SFML on VS 2022
« Reply #10 on: February 08, 2024, 03:32:56 pm »
As a default, the compiled executables are in folder in the solution root (note: not the project; all projects compile to the same folders).
x86 (32-bit) compilations will be under the configuration-type folder (e.g. Debug, Release)
x64 (64-bit) compilations will be under the folder x64 and then under the configuration-type folder (so, x64/Debug, x64/Release).

This is the default so is a good place to look. You can, however, alter these per project or even per configuration but it's not often necessary to do so.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything