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

Author Topic: Having trouble statically linking SFML for Windows (MSVC).  (Read 854 times)

0 Members and 1 Guest are viewing this topic.

BlastlessAnthony

  • Newbie
  • *
  • Posts: 5
    • View Profile
Having trouble statically linking SFML for Windows (MSVC).
« on: November 22, 2022, 08:44:33 pm »
Hello, I'm trying to make a SFML project with all the SFML libraries being static linked, I compiled SFML from source (using the latest version of MSVC and Windows SDK 10.0.19) and I've been getting errors back to back on every device I try. It always says something about clang++: fatal error LNK1120: 46 unresolved externals. I have been trying to fix this issue for several weeks and from all the research I've done I haven't been able to fix this problem.

Maybe this is a compatibility issue, who knows?

Error codes taken straight from terminal:


Makefile:12: extraneous text after 'else' directive
Linking object files ./Build/Windows/x64/Release/application.o and creating it as Binary/Windows/x64/Release/SFMLProgram.exe
clang++  -static-libgcc -static-libstdc++  -mwindows  -lsfml-graphics-s.lib -lsfml-window-s.lib -lsfml-system-s.lib -lsfml-audio-s.lib -lsfml-network-s.lib -lgdi32 -lwinmm -lopengl32 -lfreetype -lflac -lopenal32 -logg -lvorbis -lvorbisenc -lvorbisfile  "Build/Windows/x64/Release/application.o" -L./Dependencies/SFML/Windows/MSVC/x64/Release -L./Dependencies/SFML/Windows/MSVC/x64/External  -o "Binary/Windows/x64/Release/SFMLProgram.exe"
clang++: warning: argument unused during compilation: '-static-libgcc' [-Wunused-command-line-argument]
clang++: warning: argument unused during compilation: '-static-libstdc++' [-Wunused-command-line-argument]
sfml-window-s.lib(VideoModeImpl.obj) : error LNK2019: unresolved external symbol __imp_EnumDisplaySettingsW referenced in function "public: static class sf::VideoMode __cdecl sf::priv::VideoModeImpl::getDesktopMode(void)" (?getDesktopMode@VideoModeImpl@priv@sf@@SA?AVVideoMode@3@XZ)
sfml-window-s.lib(CursorImpl.obj) : error LNK2019: unresolved external symbol __imp_GetDC referenced in function "public: bool __cdecl sf::priv::CursorImpl::loadFromPixels(unsigned char const *,class sf::Vector2<unsigned int>,class sf::Vector2<unsigned int>)" (?loadFromPixels@CursorImpl@priv@sf@@QEAA_NPEBEV?$Vector2@I@3@1@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2001: unresolved external symbol __imp_GetDC
sfml-window-s.lib(WglContext.obj) : error LNK2001: unresolved external symbol __imp_GetDC
sfml-window-s.lib(CursorImpl.obj) : error LNK2019: unresolved external symbol __imp_ReleaseDC referenced in function "public: bool __cdecl sf::priv::CursorImpl::loadFromPixels(unsigned char const *,class sf::Vector2<unsigned int>,class sf::Vector2<unsigned int>)" (?loadFromPixels@CursorImpl@priv@sf@@QEAA_NPEBEV?$Vector2@I@3@1@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2001: unresolved external symbol __imp_ReleaseDC
sfml-window-s.lib(WglContext.obj) : error LNK2001: unresolved external symbol __imp_ReleaseDC
sfml-window-s.lib(CursorImpl.obj) : error LNK2019: unresolved external symbol __imp_LoadCursorW referenced in function "public: bool __cdecl sf::priv::CursorImpl::loadFromSystem(enum sf::Cursor::Type)" (?loadFromSystem@CursorImpl@priv@sf@@QEAA_NW4Type@Cursor@3@@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2001: unresolved external symbol __imp_LoadCursorW
sfml-window-s.lib(CursorImpl.obj) : error LNK2019: unresolved external symbol __imp_DestroyCursor referenced in function "public: __cdecl sf::priv::CursorImpl::~CursorImpl(void)" (??1CursorImpl@priv@sf@@QEAA@XZ)
sfml-window-s.lib(CursorImpl.obj) : error LNK2019: unresolved external symbol __imp_CreateIconIndirect referenced in function "public: bool __cdecl sf::priv::CursorImpl::loadFromPixels(unsigned char const *,class sf::Vector2<unsigned int>,class sf::Vector2<unsigned int>)" (?loadFromPixels@CursorImpl@priv@sf@@QEAA_NPEBEV?$Vector2@I@3@1@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_TrackMouseEvent referenced in function "private: void __cdecl sf::priv::WindowImplWin32::cleanup(void)" (?cleanup@WindowImplWin32@priv@sf@@AEAAXXZ)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_TranslateMessage referenced in function "protected: virtual void __cdecl sf::priv::WindowImplWin32::processEvents(void)" (?processEvents@WindowImplWin32@priv@sf@@MEAAXXZ)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_DispatchMessageW referenced in function "protected: virtual void __cdecl sf::priv::WindowImplWin32::processEvents(void)" (?processEvents@WindowImplWin32@priv@sf@@MEAAXXZ)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_PeekMessageW referenced in function "protected: virtual void __cdecl sf::priv::WindowImplWin32::processEvents(void)" (?processEvents@WindowImplWin32@priv@sf@@MEAAXXZ)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_SendMessageW referenced in function "public: virtual void __cdecl sf::priv::WindowImplWin32::setIcon(class sf::Vector2<unsigned int> const &,unsigned char const *)" (?setIcon@WindowImplWin32@priv@sf@@UEAAXAEBV?$Vector2@I@3@PEBE@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_RegisterDeviceNotificationW referenced in function "public: __cdecl sf::priv::WindowImplWin32::WindowImplWin32(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (??0WindowImplWin32@priv@sf@@QEAA@VVideoMode@2@AEBVString@2@IAEBUContextSettings@2@@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_DefWindowProcW referenced in function "private: static __int64 __cdecl sf::priv::WindowImplWin32::globalOnEvent(struct HWND__ *,unsigned int,unsigned __int64,__int64)" (?globalOnEvent@WindowImplWin32@priv@sf@@CA_JPEAUHWND__@@I_K_J@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_CallWindowProcW referenced in function "private: static __int64 __cdecl sf::priv::WindowImplWin32::globalOnEvent(struct HWND__ *,unsigned int,unsigned __int64,__int64)" (?globalOnEvent@WindowImplWin32@priv@sf@@CA_JPEAUHWND__@@I_K_J@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_RegisterClassW referenced in function "public: __cdecl sf::priv::WindowImplWin32::WindowImplWin32(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (??0WindowImplWin32@priv@sf@@QEAA@VVideoMode@2@AEBVString@2@IAEBUContextSettings@2@@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_UnregisterClassW referenced in function "public: virtual __cdecl sf::priv::WindowImplWin32::~WindowImplWin32(void)" (??1WindowImplWin32@priv@sf@@UEAA@XZ)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_CreateWindowExW referenced in function "public: __cdecl sf::priv::WindowImplWin32::WindowImplWin32(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (??0WindowImplWin32@priv@sf@@QEAA@VVideoMode@2@AEBVString@2@IAEBUContextSettings@2@@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_DestroyWindow referenced in function "public: virtual __cdecl sf::priv::WindowImplWin32::~WindowImplWin32(void)" (??1WindowImplWin32@priv@sf@@UEAA@XZ)
sfml-window-s.lib(WglContext.obj) : error LNK2001: unresolved external symbol __imp_DestroyWindow
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_ShowWindow referenced in function "public: __cdecl sf::priv::WindowImplWin32::WindowImplWin32(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (??0WindowImplWin32@priv@sf@@QEAA@VVideoMode@2@AEBVString@2@IAEBUContextSettings@2@@Z)
sfml-window-s.lib(WglContext.obj) : error LNK2001: unresolved external symbol __imp_ShowWindow
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_FlashWindowEx referenced in function "public: virtual void __cdecl sf::priv::WindowImplWin32::requestFocus(void)" (?requestFocus@WindowImplWin32@priv@sf@@UEAAXXZ)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_SetWindowPos referenced in function "public: __cdecl sf::priv::WindowImplWin32::WindowImplWin32(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (??0WindowImplWin32@priv@sf@@QEAA@VVideoMode@2@AEBVString@2@IAEBUContextSettings@2@@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_GetKeyState referenced in function "private: void __cdecl sf::priv::WindowImplWin32::processEvent(unsigned int,unsigned __int64,__int64)" (?processEvent@WindowImplWin32@priv@sf@@AEAAXI_K_J@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_MapVirtualKeyW referenced in function "private: static enum sf::Keyboard::Key __cdecl sf::priv::WindowImplWin32::virtualKeyCodeToSF(unsigned __int64,__int64)" (?virtualKeyCodeToSF@WindowImplWin32@priv@sf@@CA?AW4Key@Keyboard@3@_K_J@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_GetCapture referenced in function "private: void __cdecl sf::priv::WindowImplWin32::processEvent(unsigned int,unsigned __int64,__int64)" (?processEvent@WindowImplWin32@priv@sf@@AEAAXI_K_J@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_SetCapture referenced in function "private: void __cdecl sf::priv::WindowImplWin32::processEvent(unsigned int,unsigned __int64,__int64)" (?processEvent@WindowImplWin32@priv@sf@@AEAAXI_K_J@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_ReleaseCapture referenced in function "private: void __cdecl sf::priv::WindowImplWin32::cleanup(void)" (?cleanup@WindowImplWin32@priv@sf@@AEAAXXZ)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_GetForegroundWindow referenced in function "public: virtual bool __cdecl sf::priv::WindowImplWin32::hasFocus(void)const " (?hasFocus@WindowImplWin32@priv@sf@@UEBA_NXZ)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_SetForegroundWindow referenced in function "public: virtual void __cdecl sf::priv::WindowImplWin32::requestFocus(void)" (?requestFocus@WindowImplWin32@priv@sf@@UEAAXXZ)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_SetWindowTextW referenced in function "public: virtual void __cdecl sf::priv::WindowImplWin32::setTitle(class sf::String const &)" (?setTitle@WindowImplWin32@priv@sf@@UEAAXAEBVString@3@@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_GetClientRect referenced in function "public: virtual class sf::Vector2<unsigned int> __cdecl sf::priv::WindowImplWin32::getSize(void)const " (?getSize@WindowImplWin32@priv@sf@@UEBA?AV?$Vector2@I@3@XZ)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_GetWindowRect referenced in function "public: virtual class sf::Vector2<int> __cdecl sf::priv::WindowImplWin32::getPosition(void)const " (?getPosition@WindowImplWin32@priv@sf@@UEBA?AV?$Vector2@H@3@XZ)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_AdjustWindowRect referenced in function "public: __cdecl sf::priv::WindowImplWin32::WindowImplWin32(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (??0WindowImplWin32@priv@sf@@QEAA@VVideoMode@2@AEBVString@2@IAEBUContextSettings@2@@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_SetCursor referenced in function "private: void __cdecl sf::priv::WindowImplWin32::processEvent(unsigned int,unsigned __int64,__int64)" (?processEvent@WindowImplWin32@priv@sf@@AEAAXI_K_J@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_ScreenToClient referenced in function "private: void __cdecl sf::priv::WindowImplWin32::processEvent(unsigned int,unsigned __int64,__int64)" (?processEvent@WindowImplWin32@priv@sf@@AEAAXI_K_J@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_MapWindowPoints referenced in function "private: void __cdecl sf::priv::WindowImplWin32::grabCursor(bool)" (?grabCursor@WindowImplWin32@priv@sf@@AEAAX_N@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_ClipCursor referenced in function "private: void __cdecl sf::priv::WindowImplWin32::grabCursor(bool)" (?grabCursor@WindowImplWin32@priv@sf@@AEAAX_N@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_GetWindowLongPtrW referenced in function "public: __cdecl sf::priv::WindowImplWin32::WindowImplWin32(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (??0WindowImplWin32@priv@sf@@QEAA@VVideoMode@2@AEBVString@2@IAEBUContextSettings@2@@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_SetWindowLongPtrW referenced in function "public: __cdecl sf::priv::WindowImplWin32::WindowImplWin32(struct HWND__ *)" (??0WindowImplWin32@priv@sf@@QEAA@PEAUHWND__@@@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_GetWindowThreadProcessId referenced in function "public: virtual void __cdecl sf::priv::WindowImplWin32::requestFocus(void)" (?requestFocus@WindowImplWin32@priv@sf@@UEAAXXZ)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_CreateIcon referenced in function "public: virtual void __cdecl sf::priv::WindowImplWin32::setIcon(class sf::Vector2<unsigned int> const &,unsigned char const *)" (?setIcon@WindowImplWin32@priv@sf@@UEAAXAEBV?$Vector2@I@3@PEBE@Z)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_DestroyIcon referenced in function "public: virtual __cdecl sf::priv::WindowImplWin32::~WindowImplWin32(void)" (??1WindowImplWin32@priv@sf@@UEAA@XZ)
sfml-window-s.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp_ChangeDisplaySettingsW referenced in function "public: __cdecl sf::priv::WindowImplWin32::WindowImplWin32(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (??0WindowImplWin32@priv@sf@@QEAA@VVideoMode@2@AEBVString@2@IAEBUContextSettings@2@@Z)
sfml-window-s.lib(WglContext.obj) : error LNK2019: unresolved external symbol __imp_CreateWindowExA referenced in function "private: void __cdecl sf::priv::WglContext::createSurface(class sf::priv::WglContext *,class sf::Vector2<unsigned int> const &,unsigned int)" (?createSurface@WglContext@priv@sf@@AEAAXPEAV123@AEBV?$Vector2@I@3@I@Z)
sfml-window-s.lib(JoystickImpl.obj) : error LNK2019: unresolved external symbol __imp_RegCloseKey referenced in function "class sf::String __cdecl `anonymous namespace'::getDeviceName(unsigned int,struct tagJOYCAPSW)" (?getDeviceName@?A0xdc48ea95@@YA?AVString@sf@@IUtagJOYCAPSW@@@Z)
sfml-window-s.lib(JoystickImpl.obj) : error LNK2019: unresolved external symbol __imp_RegOpenKeyExW referenced in function "class sf::String __cdecl `anonymous namespace'::getDeviceName(unsigned int,struct tagJOYCAPSW)" (?getDeviceName@?A0xdc48ea95@@YA?AVString@sf@@IUtagJOYCAPSW@@@Z)
sfml-window-s.lib(JoystickImpl.obj) : error LNK2019: unresolved external symbol __imp_RegQueryValueExW referenced in function "class sf::String __cdecl `anonymous namespace'::getDeviceName(unsigned int,struct tagJOYCAPSW)" (?getDeviceName@?A0xdc48ea95@@YA?AVString@sf@@IUtagJOYCAPSW@@@Z)
Binary\Windows\x64\Release\SFMLProgram.exe : fatal error LNK1120: 46 unresolved externals
clang++: error: linker command failed with exit code 1120 (use -v to see invocation)
make: *** [Makefile:409: Binary/Windows/x64/Release/SFMLProgram.exe] Error 1120


The part(s) of the Makefile responsible for compiling and linking.


Library Setup

ifeq ($(msvc),1)
            linkerLibraries += \
               -L./Dependencies/SFML/Windows/MSVC/x64/Release \
               -L./Dependencies/SFML/Windows/MSVC/x64/External \

            linkerFlags += \
               -lsfml-graphics-s.lib \
               -lsfml-window-s.lib \
               -lsfml-system-s.lib \
               -lsfml-audio-s.lib \
               -lsfml-network-s.lib \
               -lgdi32 \
               -lwinmm \
               -lopengl32 \
               -lfreetype \
               -lflac \
               -lopenal32 \
               -logg \
               -lvorbis \
               -lvorbisenc \
               -lvorbisfile \

         else
                        ...



Compling and Linking.


.PHONY: all
all: $(binaryDirectory)/$(executableName)

#Link executable
$(binaryDirectory)/$(executableName):$(objects)
   @$(call echo,Linking object files $(objects) and creating it as $@)
   @$(call ReplaceDirectory,$(@D))
   $(cxxCompiler) $(linkerFlags) "$^" $(linkerLibraries) -o "$@"

#Compile sources
$(buildDirectory)/%.o:$(sourceDirectory)/%.cpp
   @$(call echo,Compiling: $< and creating it as $@)
   @$(call ReplaceDirectory,$(@D))
   $(cxxCompiler) $(cPreProcessorFlags) $(cFlags) $(includes) -c "$<" -o "$@"

#Include automatically generated dependencies
-include $(dependencies)


C++ compiler: clang++ (15..1 x64-windows-msvc)

For the record I did add the "SFML_STATIC" pre-processor flag when compiling.

kojack

  • Sr. Member
  • ****
  • Posts: 300
  • C++/C# game dev teacher.
    • View Profile
Re: Having trouble statically linking SFML for Windows (MSVC).
« Reply #1 on: November 23, 2022, 04:01:10 am »
All of the errors (well, the ones I googled for) appear to be functions from user32.lib.
Try adding -luser32 \ to your linker flags.

BlastlessAnthony

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Having trouble statically linking SFML for Windows (MSVC).
« Reply #2 on: November 23, 2022, 05:21:35 am »
Oh thanks, I guess I had removed that library or just failed to realize it. Whilst this didn't fully fix the issue I'm now down to 3 unresolved externals.

clang++: error: fatal error LNK1120: 3 unresolved externals
I will try to find the last library to fill this gap. Thanks for responding.

kojack

  • Sr. Member
  • ****
  • Posts: 300
  • C++/C# game dev teacher.
    • View Profile
Re: Having trouble statically linking SFML for Windows (MSVC).
« Reply #3 on: November 23, 2022, 07:02:57 am »
Cool.

Looking again...
I missed that the last 3 errors in the first error list are for registry functions. Those need Advapi32.lib.

 

anything