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

Author Topic: SFML Hello World project  (Read 921 times)

0 Members and 1 Guest are viewing this topic.

Nicolas Léonard

  • Newbie
  • *
  • Posts: 4
    • View Profile
SFML Hello World project
« on: May 10, 2025, 01:41:36 am »
Sorry guys.  Total newbie to SFML here.

I am trying to test if I can use SFML for a personal project.  Well, I cannot even get a basic project to run.

Using Microsoft Visual Studio Community 2017    Version 15.9.21 (installed latest updates) for C++ under Windows 10 Pro.

Followed instructions from https://www.sfml-dev.org/tutorials/3.0/getting-started/visual-studio/ 
They seem pretty straightforward:
- downloaded the SFML 3.0.0 for VS 2017 Visual C++ 16 (2019) in both 32 and 64b
- created a new "Empty Project" in VS.
- set the C++ language to ISO C++ 17 Standard
- set the include path
- set the lib path
- added the following lib dependencies: sfml-graphics.lib, sfml-window.lib and sfml-system.lib (and the -d version for Debug configurations).
- copied the dlls to the executable folder.

I used exactly the suggested code (to draw a green circle) in a file named main.cpp added to the project.

First problem: the Release versions, in either Win32 or x64 platform, fail to compile causing a compiler crash.
1>------ Rebuild All started: Project: Project1, Configuration: Release x64 ------
1>main.cpp
1>c:\sfml\sfml-3.0.0-windows-vc16-64-bit\sfml-3.0.0\include\sfml\system\exception.hpp(42): warning C4275: non dll-interface class 'std::runtime_error' used as base for dll-interface class 'sf::Exception'

Ignoring this for now and moving on to running the Debug versions.  They compile and link but crash at runtime.

Exception thrown at 0x007818ED in Project1.exe: 0xC0000005: Access violation writing location 0x7C013190.
static inline const std::size_t InvalidPos{std::u32string::npos};      [file String.hpp l. 102]

Does anyone know where the problem could be, or if there is a ready-made SFML Hello World project file somewhere?
« Last Edit: May 10, 2025, 01:44:57 am by Nicolas Léonard »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11197
    • View Profile
    • development blog
    • Email
Re: SFML Hello World project
« Reply #1 on: May 11, 2025, 08:33:19 am »
First problem: the Release versions, in either Win32 or x64 platform, fail to compile causing a compiler crash.
1>------ Rebuild All started: Project: Project1, Configuration: Release x64 ------
1>main.cpp
1>c:\sfml\sfml-3.0.0-windows-vc16-64-bit\sfml-3.0.0\include\sfml\system\exception.hpp(42): warning C4275: non dll-interface class 'std::runtime_error' used as base for dll-interface class 'sf::Exception'
It doesn't fail to compile, it's just a warning. This has been fixed in SFML 3.0.1

Exception thrown at 0x007818ED in Project1.exe: 0xC0000005: Access violation writing location 0x7C013190.
static inline const std::size_t InvalidPos{std::u32string::npos};      [file String.hpp l. 102]

Does anyone know where the problem could be, or if there is a ready-made SFML Hello World project file somewhere?
This sounds like you didn't link the SFML libs with the -d suffix in debug mode. Make sure to double check for Win32 and x64.
Also note that you need different libraries for Win32 and x64
Official FAQ: https://www.sfml-dev.org/faq/
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nicolas Léonard

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: SFML Hello World project
« Reply #2 on: Today at 01:44:11 pm »
Thanks for the reply eXpl0it3r.

Regarding the first, I was relying on the error messages
Severity   Code   Description   Project   File   Line   Suppression State
Error   C1001   An internal error has occurred in the compiler.   Project1   c:\sfml\sfml-3.0.0-windows-vc16-32-bit\sfml-3.0.0\include\sfml\system\string.hpp   1   

1>Generating code
1>c:\sfml\sfml-3.0.0-windows-vc16-32-bit\sfml-3.0.0\include\sfml\system\string.hpp(102): fatal error C1001: An internal error has occurred in the compiler.
1>(compiler file 'd:\agent\_work\1\s\src\vctools\compiler\utc\src\p2\main.c', line 187)

But it does seem to move on to trying to link:
1>LINK : fatal error LNK1000: Internal error during IMAGE::BuildImage

Regarding the failure to run:
I had dowloaded both the Win32 and x64 versions of Visual C++ 16 (2019) from the SFML download page.  I am using the Community version of VS 2019 if this makes a difference.  I restarted Windows too, just in case.

I tripled-checked that SFML-3.0.0-windows-vc16-32-bit/SFML-3.0.0\include was added to the include paths for the win32 versions and SFML-3.0.0-windows-vc16-32-bit\SFML-3.0.0\lib to the lib paths; while for the x64 versions the include paths point to SFML-3.0.0-windows-vc16-64-bit/SFML-3.0.0\include and the lib paths to SFML-3.0.0-windows-vc16-64-bit\SFML-3.0.0\lib

For the Debug configurations, additional library inputs are sfml-graphics-d.lib;sfml-window-d.lib;sfml-system-d.lib while for the Release ones the libraries are sfml-graphics.lib;sfml-window.lib;sfml-system.lib.

I also copied all win32 dlls to the win32 executable folder and same for x64.

These steps seem pretty standard to me for using an SDK in a project, and they should work in 10 minutes top, yet...  no success whatsoever.  Something in my environment?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11197
    • View Profile
    • development blog
    • Email
Re: SFML Hello World project
« Reply #3 on: Today at 02:03:31 pm »
You didn't post the compiler error in the first post ;D

In the first post I just saw that you mentioned using Visual Studio 2017, this version is no longer compatible with SFML 3. You need at least Visual Studio 2019.
In your second post you mentioned now that you are using Visual Studio 2019.

Which is it now?

Any reasons to not update to Visual Studio 2022, that brings a lot more fixes and better languages support?
Or is this a TeamCity instance (given the d:\agent\_work page)?

If you get an internal compiler error then it's definitely time to update your compiler.
SFML 3 has been built hundreds or thousands of times with VS 2019 and VS 2022 through our GitHub Actions CI, so I'm pretty confident that this is an issue with toolchain version you're using.
Official FAQ: https://www.sfml-dev.org/faq/
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nicolas Léonard

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: SFML Hello World project
« Reply #4 on: Today at 07:53:10 pm »
Well, I had tried with 2019 and then 2017 just in case, with identical results.

Quote
SFML 3 has been built hundreds or thousands of times with VS 2019 and VS 2022
Can you confrm that using the Community version is OK?

So, it looks like a case of it just ought to work.

I'll install VS 2022, just to give it a try.

Thanks for the volunteer tech support.

BTW there is a button for a 'French forum' that leads to a blank page.

Nicolas Léonard

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: SFML Hello World project
« Reply #5 on: Today at 09:04:38 pm »
For topic completeness sake: I installed VS 2022, and the same project (well editing the paths to point to SFML for VS 22) compiles and runs fine from there.

So... mystery unsolved, but I can use VS 2022.


 

anything