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

Author Topic: First Time Setup, VS Code, MinGW, Can't get default test code working  (Read 435 times)

0 Members and 1 Guest are viewing this topic.

awdjr8

  • Newbie
  • *
  • Posts: 2
    • View Profile
Hello,

I have spent way too much time trying to get the default boiler plate code working to check the overall setup with SFML.

this is the code:

#include <SFML/Graphics.hpp>


#include <optional> // Required for std::optional

using namespace sf;
using namespace std;

int main()
{
    RenderWindow window(VideoMode(Vector2u(200, 200)), "SFML works!");
    CircleShape shape(100.f);
    shape.setFillColor(Color::Green);

    while (window.isOpen())
    {
        optional<Event> event;
        while ((event = window.pollEvent()))
        {
            if (event->is<Event::Closed>()) // Check if the event is a window close event
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}



-I am on windows 10
-I used Msys2 to get minGW64 and the version is 14.2.0.
-I am sure that I downloaded the minGW version of SFML from the downloads page.
-I am sure its all the 64 bit versions of everything. (I ran the version check commands to confirm that g++ was the 64 bit version.


I am now at a fork in the road where both paths are blocked:

1. when linking dynamically using the tasks.json file:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build with MinGW",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "${workspaceFolder}/src/main.cpp",
                //"-DSFML_STATIC",
                //"-static",      // Ensure static linking
                "-o",
                "${workspaceFolder}/sfmltest",
                "-I", "C:/Libraries/SFML/include",  // Add this line to include the SFML headers
                "-L", "C:/Libraries/SFML/lib",
                "-lsfml-audio",
                "-lsfml-graphics",
                "-lsfml-network",
                "-lsfml-window",   // Make sure to link these
                "-lsfml-system"    // Make sure to link these as well
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": ["$gcc"],
            "detail": "Generated task for compiling C++"
        }
    ]
}


The build succeeds.

when running the .exe however, I get the following error:

The procedure entry point _ZNKSt25__codecvt_utf16_baselwE10do_unshiftER9_MbstatetPcS3_RS3_ could not be located in the dynamic link library C:\correctprojectdirectoryhere\sfml-system-3.dll.

The dll files are indeed beside the .exe in the project directory.



2. The other option is to try statis linking. This is the tasks.json file:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build with MinGW",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "${workspaceFolder}/src/main.cpp",
                "-DSFML_STATIC",
                "-static",      // Ensure static linking
                "-o",
                "${workspaceFolder}/sfmltest",
                "-I", "C:/Libraries/SFML/include",  // Add this line to include the SFML headers
                "-L", "C:/Libraries/SFML/lib",
                "-lsfml-audio-s",
                "-lsfml-graphics-s",
                "-lsfml-network-s",
                "-lsfml-window-s",   // Make sure to link these
                "-lsfml-system-s"    // Make sure to link these as well
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": ["$gcc"],
            "detail": "Generated task for compiling C++"
        }
    ]
}


but now building cannot succeed, with very many undefined reference errors as per the following:


Executing task: g++ -g C:\correctprojectdirectoryhere/src/main.cpp -DSFML_STATIC -static -o C:\correctprojectdirectoryhere/sfmltest -I C:/Libraries/SFML/include -L C:/Libraries/SFML/lib -lsfml-audio-s -lsfml-graphics-s -lsfml-network-s -lsfml-window-s -lsfml-system-s

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-graphics-s.a(Image.cpp.obj):Image.cpp:(.text+0x3953e): undefined reference to `std::codecvt<wchar_t, char, _Mbstatet>::codecvt(unsigned long long)&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-graphics-s.a(Image.cpp.obj):Image.cpp:(.text+0x39644): undefined reference to `std::__codecvt_utf8_utf16_base<wchar_t>::do_out(_Mbstatet&, wchar_t const*, wchar_t const*, wchar_t const*&, char*, char*, char*&) const&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-graphics-s.a(Image.cpp.obj):Image.cpp:(.text$_ZNSt10filesystem7__cxx114path10_S_convertIcEEDaPKT_S5_[_ZNSt10filesystem7__cxx114path10_S_convertIcEEDaPKT_S5_]+0x3c): undefined reference to `std::codecvt<wchar_t, char, _Mbstatet>::codecvt(unsigned long long)&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-graphics-s.a(Image.cpp.obj):Image.cpp:(.text$_ZNSt10filesystem7__cxx114path10_S_convertIcEEDaPKT_S5_[_ZNSt10filesystem7__cxx114path10_S_convertIcEEDaPKT_S5_]+0xe4): undefined reference to `std::__codecvt_utf8_utf16_base<wchar_t>::do_in(_Mbstatet&, char const*, char const*, char const*&, wchar_t*, wchar_t*, wchar_t*&) const&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-graphics-s.a(Image.cpp.obj):Image.cpp:(.rdata$_ZTVSt18codecvt_utf8_utf16IwLm1114111ELSt12codecvt_mode0EE[_ZTVSt18codecvt_utf8_utf16IwLm1114111ELSt12codecvt_mode0EE]+0x20): undefined reference to `std::__codecvt_utf8_utf16_base<wchar_t>::do_out(_Mbstatet&, wchar_t const*, wchar_t const*, wchar_t const*&, char*, char*, char*&) const&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-graphics-s.a(Image.cpp.obj):Image.cpp:(.rdata$_ZTVSt18codecvt_utf8_utf16IwLm1114111ELSt12codecvt_mode0EE[_ZTVSt18codecvt_utf8_utf16IwLm1114111ELSt12codecvt_mode0EE]+0x28): undefined reference to `std::__codecvt_utf8_utf16_base<wchar_t>::do_unshift(_Mbstatet&, char*, char*, char*&) const&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-graphics-s.a(Image.cpp.obj):Image.cpp:(.rdata$_ZTVSt18codecvt_utf8_utf16IwLm1114111ELSt12codecvt_mode0EE[_ZTVSt18codecvt_utf8_utf16IwLm1114111ELSt12codecvt_mode0EE]+0x30): undefined reference to `std::__codecvt_utf8_utf16_base<wchar_t>::do_in(_Mbstatet&, char const*, char const*, char const*&, wchar_t*, wchar_t*, wchar_t*&) const&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-graphics-s.a(Image.cpp.obj):Image.cpp:(.rdata$_ZTVSt18codecvt_utf8_utf16IwLm1114111ELSt12codecvt_mode0EE[_ZTVSt18codecvt_utf8_utf16IwLm1114111ELSt12codecvt_mode0EE]+0x48): undefined reference to `std::__codecvt_utf8_utf16_base<wchar_t>::do_length(_Mbstatet&, char const*, char const*, unsigned long long) const&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-graphics-s.a(Image.cpp.obj):Image.cpp:(.rdata$_ZTVNSt10filesystem7__cxx114path8_CodecvtIwEE[_ZTVNSt10filesystem7__cxx114path8_CodecvtIwEE]+0x20): undefined reference to `std::__codecvt_utf8_utf16_base<wchar_t>::do_out(_Mbstatet&, wchar_t const*, wchar_t const*, wchar_t const*&, char*, char*, char*&) const&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-graphics-s.a(Image.cpp.obj):Image.cpp:(.rdata$_ZTVNSt10filesystem7__cxx114path8_CodecvtIwEE[_ZTVNSt10filesystem7__cxx114path8_CodecvtIwEE]+0x28): undefined reference to `std::__codecvt_utf8_utf16_base<wchar_t>::do_unshift(_Mbstatet&, char*, char*, char*&) const&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-graphics-s.a(Image.cpp.obj):Image.cpp:(.rdata$_ZTVNSt10filesystem7__cxx114path8_CodecvtIwEE[_ZTVNSt10filesystem7__cxx114path8_CodecvtIwEE]+0x30): undefined reference to `std::__codecvt_utf8_utf16_base<wchar_t>::do_in(_Mbstatet&, char const*, char const*, char const*&, wchar_t*, wchar_t*, wchar_t*&) const&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-graphics-s.a(Image.cpp.obj):Image.cpp:(.rdata$_ZTVNSt10filesystem7__cxx114path8_CodecvtIwEE[_ZTVNSt10filesystem7__cxx114path8_CodecvtIwEE]+0x48): undefined reference to `std::__codecvt_utf8_utf16_base<wchar_t>::do_length(_Mbstatet&, char const*, char const*, unsigned long long) const&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(WindowImplWin32.cpp.obj):WindowImplWin32.cpp:(.text+0x1257): undefined reference to `__imp_GetDeviceCaps&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(WglContext.cpp.obj):WglContext.cpp:(.text+0x196): undefined reference to `__imp_SwapBuffers&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(WglContext.cpp.obj):WglContext.cpp:(.text+0x20b): undefined reference to `__imp_wglDeleteContext&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(WglContext.cpp.obj):WglContext.cpp:(.text+0x280): undefined reference to `__imp_wglMakeCurrent&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(WglContext.cpp.obj):WglContext.cpp:(.text+0x6f5): undefined reference to `__imp_wglGetProcAddress&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(WglContext.cpp.obj):WglContext.cpp:(.text+0x7ab): undefined reference to `__imp_wglDeleteContext&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(WglContext.cpp.obj):WglContext.cpp:(.text+0x828): undefined reference to `__imp_wglMakeCurrent&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(WglContext.cpp.obj):WglContext.cpp:(.text+0xb5f): undefined reference to `__imp_wglMakeCurrent&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(WglContext.cpp.obj):WglContext.cpp:(.text+0xb95): undefined reference to `__imp_wglMakeCurrent&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(WglContext.cpp.obj):WglContext.cpp:(.text+0xde6): undefined reference to `__imp_GetPixelFormat&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(WglContext.cpp.obj):WglContext.cpp:(.text+0xe15): undefined reference to `__imp_DescribePixelFormat&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(WglContext.cpp.obj):WglContext.cpp:(.text+0x1bf3): undefined reference to `__imp_ChoosePixelFormat&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(WglContext.cpp.obj):WglContext.cpp:(.text+0x2d17): undefined reference to `__imp_DescribePixelFormat&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(WglContext.cpp.obj):WglContext.cpp:(.text+0x2d26): undefined reference to `__imp_SetPixelFormat&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(WglContext.cpp.obj):WglContext.cpp:(.text+0x3ad8): undefined reference to `__imp_wglCreateContext&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(WglContext.cpp.obj):WglContext.cpp:(.text+0x3b2a): undefined reference to `__imp_wglShareLists&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(WglContext.cpp.obj):WglContext.cpp:(.text+0x3d28): undefined reference to `__imp_wglMakeCurrent&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(WglContext.cpp.obj):WglContext.cpp:(.text+0x3f7f): undefined reference to `__imp_wglMakeCurrent&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(CursorImpl.cpp.obj):CursorImpl.cpp:(.text+0x112): undefined reference to `__imp_CreateDIBSection&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(CursorImpl.cpp.obj):CursorImpl.cpp:(.text+0x174): undefined reference to `__imp_CreateBitmap&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(CursorImpl.cpp.obj):CursorImpl.cpp:(.text+0x1b0): undefined reference to `__imp_DeleteObject&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(CursorImpl.cpp.obj):CursorImpl.cpp:(.text+0x285): undefined reference to `__imp_DeleteObject&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(JoystickImpl.cpp.obj):JoystickImpl.c:(.text+0xc9a): undefined reference to `__imp_joyGetPosEx&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(JoystickImpl.cpp.obj):JoystickImpl.c:(.text+0xfde): undefined reference to `__imp_joyGetPosEx&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(JoystickImpl.cpp.obj):JoystickImpl.c:(.text+0x10d3): undefined reference to `__imp_joyGetPosEx&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(JoystickImpl.cpp.obj):JoystickImpl.c:(.text+0x1b11): undefined reference to `__imp_joyGetPosEx&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-window-s.a(JoystickImpl.cpp.obj):JoystickImpl.c:(.text+0x3fc3): undefined reference to `__imp_joyGetDevCapsW&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-system-s.a(Err.cpp.obj):Err.cpp:(.rdata+0x80): undefined reference to `std::basic_streambuf<char, std::char_traits<char> >::seekpos(std::fpos<_Mbstatet>, std::_Ios_Openmode)&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-system-s.a(Utils.cpp.obj):Utils.cpp:(.text$_ZNSt10filesystem7__cxx11lsIcSt11char_traitsIcEEERSt13basic_ostreamIT_T0_ES8_RKNS0_4pathE[_ZNSt10filesystem7__cxx11lsIcSt11char_traitsIcEEERSt13basic_ostreamIT_T0_ES8_RKNS0_4pathE]+0x4d9): undefined reference to `std::codecvt<wchar_t, char, _Mbstatet>::codecvt(unsigned long long)&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-system-s.a(Utils.cpp.obj):Utils.cpp:(.text$_ZNSt10filesystem7__cxx11lsIcSt11char_traitsIcEEERSt13basic_ostreamIT_T0_ES8_RKNS0_4pathE[_ZNSt10filesystem7__cxx11lsIcSt11char_traitsIcEEERSt13basic_ostreamIT_T0_ES8_RKNS0_4pathE]+0x5db): undefined reference to `std::__codecvt_utf8_utf16_base<wchar_t>::do_out(_Mbstatet&, wchar_t const*, wchar_t const*, wchar_t const*&, char*, char*, char*&) const&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-system-s.a(SleepImpl.cpp.obj):SleepImpl.cpp:(.text+0x2f): undefined reference to `__imp_timeBeginPeriod&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-system-s.a(SleepImpl.cpp.obj):SleepImpl.cpp:(.text+0x61): undefined reference to `__imp_timeEndPeriod&#39;
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Libraries/SFML/lib\libsfml-system-s.a(SleepImpl.cpp.obj):SleepImpl.cpp:(.text+0x74): undefined reference to `__imp_timeGetDevCaps&#39;
collect2.exe: error: ld returned 1 exit status


Any help in getting SFML working would be appreciated.

Thanks
« Last Edit: February 18, 2025, 08:25:07 am by eXpl0it3r »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11145
    • View Profile
    • development blog
    • Email
Re: First Time Setup, VS Code, MinGW, Can't get default test code working
« Reply #1 on: February 18, 2025, 08:35:29 am »
To make your life easier, we're actually recommending to use the SFML CMake Template and for VS Code to use the CMake extension, that way you can use the compiler you have and SFML is downloaded and built with your application.


The SFML download page is pretty explicit about 100% matching compilers.

Quote
The compiler versions have to match 100%!

If you want to use a MinGW package, it is not enough that the GCC versions seemingly match, you have to use one of the following matching compilers:
As the message says, it's not enough that you got the same "version" (i.e. 14.2.0) from msys2, no, they literally have to be the ones linked above or on the download page.

For static linking, you need to link all of SFML's dependencies as well, you can find a list in the Code::Blocks tutorial.
Official FAQ: https://www.sfml-dev.org/faq/
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

awdjr8

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: First Time Setup, VS Code, MinGW, Can't get default test code working
« Reply #2 on: February 21, 2025, 08:47:32 am »
Hey, thanks for the help.

I ended up replacing the mingw64 installation from Msys2 with the contents of the download from the SFML download page. I am now able to link both dynamically and statically, resulting in a working program.

I do wonder what is different about the compilers though. The devil seems to be in the details, and it is strange to me that the same version of something can actually be different.

For other people's reference, since I don't think this is actually posted anywhere, the build command with all the dependencies linked ends up looking something like:

g++ -g C:\correctprojectdirectoryhere/src/*.cpp -DSFML_STATIC -o C:\correctprojectdirectoryhere/sfmltest -I C:\correctprojectdirectoryhere/headers -lsfml-audio-s -lsfml-graphics-s -lsfml-network-s -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32 -lflac -lvorbisenc -lvorbisfile -lvorbis -logg -lws2_32 -lfreetype

looks like the slashes are all over the place, but that is what my vscode is telling me in the terminal.

for reference, my tasks.json args look like:

"args": [
                "-g",
                "${workspaceFolder}/src/*.cpp",
                "-DSFML_STATIC",
                //"-static",      // Ensure static linking
                "-o",
                "${workspaceFolder}/sfmltest",
                "-I", "${workspaceFolder}/headers",
                //"-I", "C:/Libraries/SFML/include",  // Add this line to include the SFML headers
                //"-L", "C:/Libraries/SFML/lib",
                "-lsfml-audio-s",
                "-lsfml-graphics-s",
                "-lsfml-network-s",
                "-lsfml-window-s",   // Make sure to link these
                "-lsfml-system-s",    // Make sure to link these as well
                "-lopengl32",
                "-lwinmm",
                "-lgdi32",
                "-lflac",
                "-lvorbisenc",
                "-lvorbisfile",
                "-lvorbis",
                "-logg",
                "-lws2_32",
                "-lfreetype"
            ],

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11145
    • View Profile
    • development blog
    • Email
Re: First Time Setup, VS Code, MinGW, Can't get default test code working
« Reply #3 on: February 21, 2025, 09:25:10 am »
I do wonder what is different about the compilers though. The devil seems to be in the details, and it is strange to me that the same version of something can actually be different.
While they may be compiled from the same source, there are many, many configuration options, the major contributor is however likely the integration with tooling/environments. MSYS2 as "Linux" environment will come with a lot of other tooling and libraries already existing, while a standalone MinGW-w64 build will have to build their own runtime libraries and binutils. So eventually you end up with slightly different runtime libs that are incompatible with each other.
Official FAQ: https://www.sfml-dev.org/faq/
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/