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

Author Topic: Can't setup SFML 2.6 with VSCode on Windows  (Read 403 times)

0 Members and 1 Guest are viewing this topic.

timedog

  • Newbie
  • *
  • Posts: 3
    • View Profile
Can't setup SFML 2.6 with VSCode on Windows
« on: September 25, 2023, 08:54:55 am »
I got it working with Visual Studio, but decided that Visual Studio is really clunky and would rather just use VSCode. I've found a bunch of tutorials on doing this for previous versions, installing mingw and creating a Makefile and what not, but not for 2.6.

I spent the entire day trying to figure this out with bits and scraps of info from various sources. I can do a "make" command and it builds a main.exe file, but when I run the file no window shows up. I'm assuming I have the wrong version of something somewhere. Or maybe my previous installation of git bash terminal is messing with something?

Here's what I've done to get this far.
  • Installed mingw32 from this installer: https://github.com/niXman/mingw-builds-binaries

    Mingw installer options I chose:
    • Version: 13.1.0
    • Thread Model: posix
    • Architecture: 32-bit
    • Build Revision: rev1
    • C Runtime: ucrt
    • Directory for Installation: C:/
  • Went into the C:/mingw32/bin folder and went to the file "mingw32-make.exe" and renamed it to simply "make.exe"
  • From SFML Download page, downloaded: GCC 13.1.0 MinGW (DW2) - 32-bit
  • From that SFML download, copied the "lib" and "include" folders into this directory in my project: <project root>/src/
  • Added the files from the "/bin" folder in my SFML download into the root directory of my project, next to main.cpp, and Makefile.
  • Changed these settings in my VSCode settings file:
    • "C_Cpp.default.compilerPath": "C:/mingw32/bin/g++.exe",
    • "C_Cpp.default.includePath": ["${workspaceFolder}/**"]
  • Added Path variable "C:/mingw32/bin" for my Windows User (not System)
  • Added demo code from SFML site to main.cpp in my project, a green circle should pop up when running the program.
  • Ran "make" command in VSCode terminal from my project directory. This worked and created a "main.exe" file.
  • Ran "./main.exe" from the same place. This seemed to work, there were no errors or messages, but nothing popped up on my screen.

I feel like most of this is correct if I'm actually compiling and running the executable. Maybe I chose the wrong mingw installation? Can anyone advise on what I'm doing wrong?
« Last Edit: September 25, 2023, 11:54:42 pm by timedog »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10777
    • View Profile
    • development blog
    • Email
Re: Can't setup SFML 2.6 with VSCode on Windows
« Reply #1 on: September 26, 2023, 08:03:35 am »
  • Installed mingw32 from this installer: https://github.com/niXman/mingw-builds-binaries

    Mingw installer options I chose:
    • Version: 13.1.0
    • Thread Model: posix
    • Architecture: 32-bit
    • Build Revision: rev1
    • C Runtime: ucrt
    • Directory for Installation: C:/
  • ...
  • From SFML Download page, downloaded: GCC 13.1.0 MinGW (DW2) - 32-bit
You missed the red box on the top of the download page that tells you, your compiler has to match 100% and a link to the specific compiler. The UCRT version will cause troubles with some of the pre-built binaries.

Personally, I highly recommend to install the CMake extension in VS Code and just use the SFML CMake Template, which also downloads and build SFML for you. It's much more flexible than handcrafting some makefile[/list]
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

timedog

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Can't setup SFML 2.6 with VSCode on Windows
« Reply #2 on: September 27, 2023, 07:19:52 am »
I didn't miss it, if you're talking about the box that mentions Visual Studio, I just don't know how to interpret that information outside of the context of Visual Studio use. How do I check which compiler my package is using? How do I find a mingw package with the correct compiler? I have no clue where to even start with figuring that out, nor did I have any clue that that information was applicable outside of Visual Studio use. If I did have a clue it would not have been necessary to create a post here, and I did so only after spending an entire day trying to figure this out. 

I did use that compiler information to download the correct SFML package for Visual Studio 2022, and everything worked fine there. I just think Visual Studio is clunky. Maybe I'll use both VSCode and Visual Studio though, only going to Visual Studio when doing heavy debugging, but using VSCode for most tasks.   

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10777
    • View Profile
    • development blog
    • Email
Re: Can't setup SFML 2.6 with VSCode on Windows
« Reply #3 on: September 27, 2023, 08:13:48 am »
I mean it's right inside that box:

Quote
Here are links to the specific MinGW compiler versions used to build the provided packages:
WinLibs MSVCRT 13.1.0 (32-bit), WinLibs MSVCRT 13.1.0 (64-bit)

If you aren't using exactly the same compiler as linked, you can't use the MinGW pre-compiled binaries.
That means, you don't really have to check what version your current compiler is, but you have to either download the linked compiler or build SFML from source.

I've no idea what you mean with VS being clunky, but that's your decision. If you stick with VS Code, I continue recommending using CMake and if you do use CMake, I recommend to make use of the SFML CMake Template as linked above.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

timedog

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Can't setup SFML 2.6 with VSCode on Windows
« Reply #4 on: September 28, 2023, 06:58:35 am »
Okay, I get it now. It was not obvious to me that those links were mingw, because I'm a beginner. I've now made a working VSCode SFML 2.6 Template repo including text instructions so I don't have to remember this stuff again. Thanks.

The only problem now is that I don't know how to create separate debug and normal releases with make (unless the exe is exactly the same between debug and normal, and the only difference is the dll files used). Probably need to do more research.