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

Author Topic: Can't static link SFML  (Read 1513 times)

0 Members and 2 Guests are viewing this topic.

L1NTHALO

  • Newbie
  • *
  • Posts: 3
    • View Profile
Can't static link SFML
« on: February 13, 2024, 01:41:41 pm »
Hello, I've tried linking the SFML library statically in Visual Studio 2022 but I can't get it to work.

I followed the tutorial step by step and I'm pretty sure I did everything correctly.
I choose the 32-bit SFML lib and also have the x86/Win32 configuration in VS.
I also added the additional dependencies (with the s and d suffix) and all my paths seem to be correct.


The only thing that I could think of is that I have the wrong compiler version. I downloaded the WinLibs MSVCRT 13.1.0 but the problem is I have no idea how to install/change the version to the correct one and also found no way to after researching since I don't even know what to google precisely.

Help would be greatly appreciated  :) :)

Below is my code and the build log:
Code: [Select]
#include "SFML/Graphics.hpp"
#include "SFML/System.hpp"
#include "SFML/Window.hpp"

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

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

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

    return 0;
}

Code: [Select]
Build started...
1>------ Build started: Project: sfmlTest, Configuration: Debug Win32 ------
1>Microsoft (R) C/C++ Optimizing Compiler Version 19.37.32825 for x86
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>cl /c /IC:\Dev\Projects\sfmlTest\Dependencies\SFML\include /ZI /JMC /W4 /WX- /diagnostics:column /sdl /Od /Oy- /D SFML_STATIC /D WIN32 /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /std:c++17 /permissive- /Fo"C:\Dev\Projects\sfmlTest\bin\intermediates\Win32\Debug\\" /Fd"C:\Dev\Projects\sfmlTest\bin\intermediates\Win32\Debug\vc143.pdb" /external:W4 /Gd /TP /analyze- /FC /errorReport:prompt src\main.cpp
1>main.cpp
1>Microsoft (R) Incremental Linker Version 14.37.32825.0
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>"/OUT:C:\Dev\Projects\sfmlTest\bin\Win32\Debug\sfmlTest.exe" /INCREMENTAL "/ILK:C:\Dev\Projects\sfmlTest\bin\intermediates\Win32\Debug\sfmlTest.ilk" /LIBPATH:C:\Dev\Projects\sfmlTest\Dependencies\SFML\lib winmm.lib "sfml-system-s-d.lib" opengl32.lib gdi32.lib "sfml-window-s-d.lib" freetype.lib "sfml-graphics-s-d.lib" /MANIFEST "/MANIFESTUAC:level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG "/PDB:C:\Dev\Projects\sfmlTest\bin\Win32\Debug\sfmlTest.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT "/IMPLIB:C:\Dev\Projects\sfmlTest\bin\Win32\Debug\sfmlTest.lib" /MACHINE:X86 C:\Dev\Projects\sfmlTest\bin\intermediates\Win32\Debug\main.obj
1>sfml-window-s-d.lib(VideoModeImpl.obj) : error LNK2019: unresolved external symbol __imp__EnumDisplaySettingsW@12 referenced in function "public: static class std::vector<class sf::VideoMode,class std::allocator<class sf::VideoMode> > __cdecl sf::priv::VideoModeImpl::getFullscreenModes(void)" (?getFullscreenModes@VideoModeImpl@priv@sf@@SA?AV?$vector@VVideoMode@sf@@V?$allocator@VVideoMode@sf@@@std@@@std@@XZ)
1>sfml-window-s-d.lib(CursorImpl.obj) : error LNK2019: unresolved external symbol __imp__GetDC@4 referenced in function "public: bool __thiscall sf::priv::CursorImpl::loadFromPixels(unsigned char const *,class sf::Vector2<unsigned int>,class sf::Vector2<unsigned int>)" (?loadFromPixels@CursorImpl@priv@sf@@QAE_NPBEV?$Vector2@I@3@1@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2001: unresolved external symbol __imp__GetDC@4
1>sfml-window-s-d.lib(WglContext.obj) : error LNK2001: unresolved external symbol __imp__GetDC@4
1>sfml-window-s-d.lib(CursorImpl.obj) : error LNK2019: unresolved external symbol __imp__ReleaseDC@8 referenced in function "public: bool __thiscall sf::priv::CursorImpl::loadFromPixels(unsigned char const *,class sf::Vector2<unsigned int>,class sf::Vector2<unsigned int>)" (?loadFromPixels@CursorImpl@priv@sf@@QAE_NPBEV?$Vector2@I@3@1@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2001: unresolved external symbol __imp__ReleaseDC@8
1>sfml-window-s-d.lib(WglContext.obj) : error LNK2001: unresolved external symbol __imp__ReleaseDC@8
1>sfml-window-s-d.lib(CursorImpl.obj) : error LNK2019: unresolved external symbol __imp__LoadCursorW@8 referenced in function "public: bool __thiscall sf::priv::CursorImpl::loadFromSystem(enum sf::Cursor::Type)" (?loadFromSystem@CursorImpl@priv@sf@@QAE_NW4Type@Cursor@3@@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2001: unresolved external symbol __imp__LoadCursorW@8
1>sfml-window-s-d.lib(CursorImpl.obj) : error LNK2019: unresolved external symbol __imp__DestroyCursor@4 referenced in function "private: void __thiscall sf::priv::CursorImpl::release(void)" (?release@CursorImpl@priv@sf@@AAEXXZ)
1>sfml-window-s-d.lib(CursorImpl.obj) : error LNK2019: unresolved external symbol __imp__CreateIconIndirect@4 referenced in function "public: bool __thiscall sf::priv::CursorImpl::loadFromPixels(unsigned char const *,class sf::Vector2<unsigned int>,class sf::Vector2<unsigned int>)" (?loadFromPixels@CursorImpl@priv@sf@@QAE_NPBEV?$Vector2@I@3@1@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__TrackMouseEvent@4 referenced in function "private: void __thiscall sf::priv::WindowImplWin32::setTracking(bool)" (?setTracking@WindowImplWin32@priv@sf@@AAEX_N@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__TranslateMessage@4 referenced in function "protected: virtual void __thiscall sf::priv::WindowImplWin32::processEvents(void)" (?processEvents@WindowImplWin32@priv@sf@@MAEXXZ)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__DispatchMessageW@4 referenced in function "protected: virtual void __thiscall sf::priv::WindowImplWin32::processEvents(void)" (?processEvents@WindowImplWin32@priv@sf@@MAEXXZ)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__PeekMessageW@20 referenced in function "protected: virtual void __thiscall sf::priv::WindowImplWin32::processEvents(void)" (?processEvents@WindowImplWin32@priv@sf@@MAEXXZ)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__SendMessageW@16 referenced in function "public: virtual void __thiscall sf::priv::WindowImplWin32::setIcon(unsigned int,unsigned int,unsigned char const *)" (?setIcon@WindowImplWin32@priv@sf@@UAEXIIPBE@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__RegisterDeviceNotificationW@12 referenced in function "public: __thiscall sf::priv::WindowImplWin32::WindowImplWin32(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (??0WindowImplWin32@priv@sf@@QAE@VVideoMode@2@ABVString@2@IABUContextSettings@2@@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__DefWindowProcW@16 referenced in function "private: static long __stdcall sf::priv::WindowImplWin32::globalOnEvent(struct HWND__ *,unsigned int,unsigned int,long)" (?globalOnEvent@WindowImplWin32@priv@sf@@CGJPAUHWND__@@IIJ@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__CallWindowProcW@20 referenced in function "private: static long __stdcall sf::priv::WindowImplWin32::globalOnEvent(struct HWND__ *,unsigned int,unsigned int,long)" (?globalOnEvent@WindowImplWin32@priv@sf@@CGJPAUHWND__@@IIJ@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__RegisterClassW@4 referenced in function "private: void __thiscall sf::priv::WindowImplWin32::registerWindowClass(void)" (?registerWindowClass@WindowImplWin32@priv@sf@@AAEXXZ)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__UnregisterClassW@8 referenced in function "public: virtual __thiscall sf::priv::WindowImplWin32::~WindowImplWin32(void)" (??1WindowImplWin32@priv@sf@@UAE@XZ)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__CreateWindowExW@48 referenced in function "public: __thiscall sf::priv::WindowImplWin32::WindowImplWin32(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (??0WindowImplWin32@priv@sf@@QAE@VVideoMode@2@ABVString@2@IABUContextSettings@2@@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__DestroyWindow@4 referenced in function "public: virtual __thiscall sf::priv::WindowImplWin32::~WindowImplWin32(void)" (??1WindowImplWin32@priv@sf@@UAE@XZ)
1>sfml-window-s-d.lib(WglContext.obj) : error LNK2001: unresolved external symbol __imp__DestroyWindow@4
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__ShowWindow@8 referenced in function "public: virtual void __thiscall sf::priv::WindowImplWin32::setVisible(bool)" (?setVisible@WindowImplWin32@priv@sf@@UAEX_N@Z)
1>sfml-window-s-d.lib(WglContext.obj) : error LNK2001: unresolved external symbol __imp__ShowWindow@8
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__FlashWindowEx@4 referenced in function "public: virtual void __thiscall sf::priv::WindowImplWin32::requestFocus(void)" (?requestFocus@WindowImplWin32@priv@sf@@UAEXXZ)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__SetWindowPos@28 referenced in function "public: virtual void __thiscall sf::priv::WindowImplWin32::setPosition(class sf::Vector2<int> const &)" (?setPosition@WindowImplWin32@priv@sf@@UAEXABV?$Vector2@H@3@@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__GetKeyState@4 referenced in function "private: void __thiscall sf::priv::WindowImplWin32::processEvent(unsigned int,unsigned int,long)" (?processEvent@WindowImplWin32@priv@sf@@AAEXIIJ@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__MapVirtualKeyW@8 referenced in function "private: static enum sf::Keyboard::Key __cdecl sf::priv::WindowImplWin32::virtualKeyCodeToSF(unsigned int,long)" (?virtualKeyCodeToSF@WindowImplWin32@priv@sf@@CA?AW4Key@Keyboard@3@IJ@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__GetCapture@0 referenced in function "private: void __thiscall sf::priv::WindowImplWin32::processEvent(unsigned int,unsigned int,long)" (?processEvent@WindowImplWin32@priv@sf@@AAEXIIJ@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__SetCapture@4 referenced in function "private: void __thiscall sf::priv::WindowImplWin32::processEvent(unsigned int,unsigned int,long)" (?processEvent@WindowImplWin32@priv@sf@@AAEXIIJ@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__ReleaseCapture@0 referenced in function "private: void __thiscall sf::priv::WindowImplWin32::cleanup(void)" (?cleanup@WindowImplWin32@priv@sf@@AAEXXZ)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__GetForegroundWindow@0 referenced in function "public: virtual void __thiscall sf::priv::WindowImplWin32::requestFocus(void)" (?requestFocus@WindowImplWin32@priv@sf@@UAEXXZ)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__SetForegroundWindow@4 referenced in function "public: virtual void __thiscall sf::priv::WindowImplWin32::requestFocus(void)" (?requestFocus@WindowImplWin32@priv@sf@@UAEXXZ)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__SetWindowTextW@8 referenced in function "public: virtual void __thiscall sf::priv::WindowImplWin32::setTitle(class sf::String const &)" (?setTitle@WindowImplWin32@priv@sf@@UAEXABVString@3@@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__GetClientRect@8 referenced in function "public: virtual class sf::Vector2<unsigned int> __thiscall sf::priv::WindowImplWin32::getSize(void)const " (?getSize@WindowImplWin32@priv@sf@@UBE?AV?$Vector2@I@3@XZ)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__GetWindowRect@8 referenced in function "public: virtual class sf::Vector2<int> __thiscall sf::priv::WindowImplWin32::getPosition(void)const " (?getPosition@WindowImplWin32@priv@sf@@UBE?AV?$Vector2@H@3@XZ)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__AdjustWindowRect@12 referenced in function "public: __thiscall sf::priv::WindowImplWin32::WindowImplWin32(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (??0WindowImplWin32@priv@sf@@QAE@VVideoMode@2@ABVString@2@IABUContextSettings@2@@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__SetCursor@4 referenced in function "public: virtual void __thiscall sf::priv::WindowImplWin32::setMouseCursorVisible(bool)" (?setMouseCursorVisible@WindowImplWin32@priv@sf@@UAEX_N@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__ScreenToClient@8 referenced in function "private: void __thiscall sf::priv::WindowImplWin32::processEvent(unsigned int,unsigned int,long)" (?processEvent@WindowImplWin32@priv@sf@@AAEXIIJ@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__MapWindowPoints@16 referenced in function "private: void __thiscall sf::priv::WindowImplWin32::grabCursor(bool)" (?grabCursor@WindowImplWin32@priv@sf@@AAEX_N@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__ClipCursor@4 referenced in function "private: void __thiscall sf::priv::WindowImplWin32::grabCursor(bool)" (?grabCursor@WindowImplWin32@priv@sf@@AAEX_N@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__GetWindowLongW@8 referenced in function "public: virtual void __thiscall sf::priv::WindowImplWin32::setSize(class sf::Vector2<unsigned int> const &)" (?setSize@WindowImplWin32@priv@sf@@UAEXABV?$Vector2@I@3@@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__SetWindowLongW@12 referenced in function "public: __thiscall sf::priv::WindowImplWin32::WindowImplWin32(struct HWND__ *)" (??0WindowImplWin32@priv@sf@@QAE@PAUHWND__@@@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__GetWindowThreadProcessId@8 referenced in function "public: virtual void __thiscall sf::priv::WindowImplWin32::requestFocus(void)" (?requestFocus@WindowImplWin32@priv@sf@@UAEXXZ)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__CreateIcon@28 referenced in function "public: virtual void __thiscall sf::priv::WindowImplWin32::setIcon(unsigned int,unsigned int,unsigned char const *)" (?setIcon@WindowImplWin32@priv@sf@@UAEXIIPBE@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__DestroyIcon@4 referenced in function "public: virtual __thiscall sf::priv::WindowImplWin32::~WindowImplWin32(void)" (??1WindowImplWin32@priv@sf@@UAE@XZ)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__ChangeDisplaySettingsW@8 referenced in function "private: void __thiscall sf::priv::WindowImplWin32::switchToFullscreen(class sf::VideoMode const &)" (?switchToFullscreen@WindowImplWin32@priv@sf@@AAEXABVVideoMode@3@@Z)
1>sfml-window-s-d.lib(WglContext.obj) : error LNK2019: unresolved external symbol __imp__CreateWindowExA@48 referenced in function "private: void __thiscall sf::priv::WglContext::createSurface(class sf::priv::WglContext *,unsigned int,unsigned int,unsigned int)" (?createSurface@WglContext@priv@sf@@AAEXPAV123@III@Z)
1>sfml-window-s-d.lib(JoystickImpl.obj) : error LNK2019: unresolved external symbol __imp__RegCloseKey@4 referenced in function "class sf::String __cdecl `anonymous namespace'::getDeviceName(unsigned int,struct tagJOYCAPSW)" (?getDeviceName@?A0x8b8a5189@@YA?AVString@sf@@IUtagJOYCAPSW@@@Z)
1>sfml-window-s-d.lib(JoystickImpl.obj) : error LNK2019: unresolved external symbol __imp__RegOpenKeyExW@20 referenced in function "class sf::String __cdecl `anonymous namespace'::getDeviceName(unsigned int,struct tagJOYCAPSW)" (?getDeviceName@?A0x8b8a5189@@YA?AVString@sf@@IUtagJOYCAPSW@@@Z)
1>sfml-window-s-d.lib(JoystickImpl.obj) : error LNK2019: unresolved external symbol __imp__RegQueryValueExW@24 referenced in function "class sf::String __cdecl `anonymous namespace'::getDeviceName(unsigned int,struct tagJOYCAPSW)" (?getDeviceName@?A0x8b8a5189@@YA?AVString@sf@@IUtagJOYCAPSW@@@Z)
1>C:\Dev\Projects\sfmlTest\bin\Win32\Debug\sfmlTest.exe : fatal error LNK1120: 46 unresolved externals
1>Done building project "sfmlTest.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build started at 13:26 and took 01,855 seconds ==========

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: Can't static link SFML
« Reply #1 on: February 13, 2024, 02:55:38 pm »
If we pick one error line and take a look at it:
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__SetWindowLongW@12 referenced in function "public: __thiscall sf::priv::WindowImplWin32::WindowImplWin32(struct HWND__ *)" (??0WindowImplWin32@priv@sf@@QAE@PAUHWND__@@@Z)

The key parts: "unresolved external symbol" means it can't find something (most likely because a library is missing), and the next symbol is __imp__SetWindowLongW. If we ignore the __imp__ part and google for SetWindowLongW, Microsoft's documentation is here: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowlongw
Down the bottom of that page it says SetWindowLongW is part of user32.lib.
(Looks like all of the other error lines are also things from user32.lib.

Looking at the linker line, user32.lib isn't listed, so it needs to be added.


L1NTHALO

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Can't static link SFML
« Reply #2 on: February 13, 2024, 04:17:23 pm »
Thank you very much!! Advapi32.lib was also missing.
Do you know why these would be missing? Because they weren't listed in the dependencies in the tutorial.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Can't static link SFML
« Reply #3 on: February 13, 2024, 06:32:14 pm »
Hello
Hello! :)

linking the SFML library statically in Visual Studio 2022
I downloaded the WinLibs MSVCRT 13.1.0
The WinLibs are for the MinGW compiler. Since you're using the latest version of Visual Studio, those are not needed and the download 'does not need to match 100%'.
With the rest of the information of your configuration, can we presume that you downloaded this one: "Visual C++ 17 (2022) - 32-bit"?

In addition, don't forget to define the SFML_STATIC macro in Preprocessor Definitions (when building statically).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*