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

Author Topic: error LNK2001 when linking statically  (Read 1007 times)

0 Members and 1 Guest are viewing this topic.

super_surviveur

  • Guest
error LNK2001 when linking statically
« on: September 05, 2022, 08:11:55 pm »
Hi !
I'm currently creating a python module who use SFML. I want to compile the module statically, so I added the SFML_STATIC preprocessor option and i pass this `sfml-graphics-s sfml-window-s sfml-system-s opengl32 freetype winmm gdi32` to the linker. I use MSVC. But this give me this error:

Code: [Select]
      sfml-window-s.lib(VideoModeImpl.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_EnumDisplaySettingsW
      sfml-window-s.lib(CursorImpl.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_GetDC
      sfml-window-s.lib(WglContext.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_GetDC
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_GetDC
      sfml-window-s.lib(CursorImpl.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_ReleaseDC
      sfml-window-s.lib(WglContext.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_ReleaseDC
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_ReleaseDC
      sfml-window-s.lib(CursorImpl.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_LoadCursorW
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_LoadCursorW
      sfml-window-s.lib(CursorImpl.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_DestroyCursor
      sfml-window-s.lib(CursorImpl.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_CreateIconIndirect
      sfml-window-s.lib(CursorImpl.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_CopyIcon
      sfml-window-s.lib(WglContext.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_CreateWindowExA
      sfml-window-s.lib(WglContext.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_DestroyWindow
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_DestroyWindow
      sfml-window-s.lib(WglContext.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_ShowWindow
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_ShowWindow
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_TrackMouseEvent
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_TranslateMessage
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_DispatchMessageW
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_PeekMessageW
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_SendMessageW
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_RegisterDeviceNotificationW
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_DefWindowProcW
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_CallWindowProcW
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_RegisterClassW
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_UnregisterClassW
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_CreateWindowExW
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_FlashWindowEx
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_SetWindowPos
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_GetKeyState
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_MapVirtualKeyW
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_GetCapture
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_SetCapture
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_ReleaseCapture
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_GetForegroundWindow
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_SetForegroundWindow
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_SetWindowTextW
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_GetClientRect
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_GetWindowRect
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_AdjustWindowRect
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_ShowCursor
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_SetCursor
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_ScreenToClient
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_MapWindowPoints
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_ClipCursor
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_GetWindowLongW
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_SetWindowLongW
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_GetWindowLongPtrW
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_SetWindowLongPtrW
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_CreateIcon
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_DestroyIcon
      sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_ChangeDisplaySettingsW
      sfml-window-s.lib(JoystickImpl.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_RegCloseKey
      sfml-window-s.lib(JoystickImpl.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_RegOpenKeyExW
      sfml-window-s.lib(JoystickImpl.cpp.obj) : error LNK2001: symbole externe non r‚solu __imp_RegQueryValueExW
      build\lib.win-amd64-cpython-39\pyTileSFML.cp39-win_amd64.pyd : fatal error LNK1120: 50 externes non r‚solus

The python setup script generate this linker command:
Code: [Select]
D:\VisualStudioIDE\VC\Tools\MSVC\14.33.31629\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:D:/code/pyTileSFML/SFML-2.5.1/lib /LIBPATH:C:\Users\julie\AppData\Local\Programs\Python\Python39\libs /LIBPATH:C:\Users\julie\AppData\Local\Programs\Python\Python39 /LIBPATH:C:\Users\julie\AppData\Local\Programs\Python\Python39\PCbuild\amd64 /LIBPATH:D:\VisualStudioIDE\VC\Tools\MSVC\14.33.31629\lib\x64 "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\\lib\10.0.19041.0\\um\x64" gdi32.lib winmm.lib freetype.lib opengl32.lib sfml-system-s.lib sfml-window-s.lib sfml-graphics-s.lib /EXPORT:PyInit_pyTileSFML build\temp.win-amd64-cpython-39\Release\src/PyWindow.obj build\temp.win-amd64-cpython-39\Release\src/main.obj /OUT:build\lib.win-amd64-cpython-39\pyTileSFML.cp39-win_amd64.pyd /IMPLIB:build\temp.win-amd64-cpython-39\Release\src\pyTileSFML.cp39-win_amd64.lib

If i compile without -s, and i add dlls, the module works perfectly.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: error LNK2001 when linking statically
« Reply #1 on: September 05, 2022, 10:05:05 pm »
Seems like you accidentally removed the additional libraries that VS links by default, but requires that they are listed in the library config.
I don't really know the exact name or variable to add, but LoadCursorW for examples comes from winuser.
If you create a new project, they'll be listed in there, make sure to not delete the field before entering the SFML libraries
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

super_surviveur

  • Guest
Re: error LNK2001 when linking statically
« Reply #2 on: September 06, 2022, 07:35:45 am »
Oh, I build the project without VS, so I think the problem come from here. Do you know where I can find a list of the dependencies added by VS?
Thank you

EDIT: I found the 2 missing libs: user32 and advapi32, I added the lib manually to the linker and it works perfectly. I will try to add sfml-audio-s and sfml-network-s.
Thanks

EDIT 2:
all dependencies are listed in the setup.py file of python-SFML (https://github.com/intjelic/python-sfml/blob/master/setup.py)
Code: [Select]
if platform.system() == 'Windows':
     system_libs = [
         'winmm',
         'sfml-system-s'
     ]
     window_libs = [
       'user32',
       'advapi32',
       'winmm',
       'sfml-system-s',
       'gdi32',
       'opengl32',
       'sfml-window-s'
     ]
     graphics_libs = [
         'user32',
         'advapi32',
         'winmm',
         'sfml-system-s',
         'gdi32',
         'opengl32',
         'sfml-window-s',
         'freetype',
         'jpeg',
         'sfml-graphics-s'
     ]
     audio_libs = [
         'winmm',
         'sfml-system-s',
         'flac',
         'vorbisenc',
         'vorbisfile',
         'vorbis',
         'ogg',
         'openal32',
         'sfml-audio-s'
     ]
     network_libs = [
         'ws2_32',
         'sfml-system-s',
         'sfml-network-s'
     ]
 else:
     system_libs   = ['sfml-system']
     window_libs   = ['sfml-system', 'sfml-window']
     graphics_libs = ['sfml-system', 'sfml-window', 'sfml-graphics']
     audio_libs    = ['sfml-system', 'sfml-audio']
     network_libs  = ['sfml-system', 'sfml-network']
« Last Edit: September 08, 2022, 03:54:52 pm by super_surviveur »