SFML community forums

Help => Window => Topic started by: Lime Liquid on February 08, 2023, 05:57:32 pm

Title: Getting error with linker - __imp_ files are missing.
Post by: Lime Liquid on February 08, 2023, 05:57:32 pm
This is not my first time working with SFML, I just created new project. Linked everything correctly, even defined SFML_STATIC variable in preprocessor C++ Caterogy. I'm getting bunch errors for Release, such as:

sfml-window-s.lib(VideoModeImpl.cpp.obj) : error LNK2001: unresolved external symbol __imp_EnumDisplaySettingsW
sfml-window-s.lib(CursorImpl.cpp.obj) : error LNK2001: unresolved external symbol __imp_GetDC
sfml-window-s.lib(WglContext.cpp.obj) : error LNK2001: unresolved external symbol __imp_GetDC
sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: unresolved external symbol __imp_GetDC
sfml-window-s.lib(CursorImpl.cpp.obj) : error LNK2001: unresolved external symbol __imp_ReleaseDC
sfml-window-s.lib(WglContext.cpp.obj) : error LNK2001: unresolved external symbol __imp_ReleaseDC
sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2001: unresolved external symbol __imp_ReleaseDC

There are totally 50 linker errors like this.
Visual Studio 2022, C++ 14 with SFML-2.5.1

Any help?
Title: Re: Getting error with linker - __imp_ files are missing.
Post by: eXpl0it3r on February 09, 2023, 12:11:49 am
As mentioned in the Getting Started tutorials, once you link SFML statically, you'll also have to specify SFML's dependencies.

See the table for which libraries are needed: https://www.sfml-dev.org/tutorials/2.5/start-vc.php

You can just add them to the linker settings without having to know their location, as the linker already knows that.
Title: Re: Getting error with linker - __imp_ files are missing.
Post by: Lime Liquid on February 09, 2023, 08:38:19 am
As mentioned in the Getting Started tutorials, once you link SFML statically, you'll also have to specify SFML's dependencies.

See the table for which libraries are needed: https://www.sfml-dev.org/tutorials/2.5/start-vc.php

You can just add them to the linker settings without having to know their location, as the linker already knows that.
I already linked everything right. I suppose that it is sfml-window-s.lib that makes those 50 errors...

I have linked in Linker - Input : opengl32.lib;winmm.lib;freetype.lib;gdi32.lib;sfml-graphics-s.lib;sfml-window-s.lib;sfml-system-s.lib

Sorry for any inconvenience,
Title: Re: Getting error with linker - __imp_ files are missing.
Post by: kojack on February 09, 2023, 09:04:22 am
The functions mentioned in the errors are all from user32.lib, you need to add it to the linker input.
Title: Re: Getting error with linker - __imp_ files are missing.
Post by: Lime Liquid on February 10, 2023, 08:59:53 am
The functions mentioned in the errors are all from user32.lib, you need to add it to the linker input.

This still doesn't fix all of the errors. Now linker.exe exits with code 1120, and I get 3 errors:

sfml-window-s.lib(JoystickImpl.cpp.obj) : error LNK2001: unresolved external symbol __imp_RegCloseKey
sfml-window-s.lib(JoystickImpl.cpp.obj) : error LNK2001: unresolved external symbol __imp_RegOpenKeyExW
sfml-window-s.lib(JoystickImpl.cpp.obj) : error LNK2001: unresolved external symbol __imp_RegQueryValueExW

Thanks anyway for your try!
Title: Re: Getting error with linker - __imp_ files are missing.
Post by: eXpl0it3r on February 10, 2023, 11:02:39 am
You shouldn't have removed the libraries that were already listed, those are the once which are now failing.

You can easily find out which ones are missing, by copy pasting the function name after imp_ into a web search engine, which will then point you to a MSDN documentation page and at the bottom of that page you'll see in which library that function exists.

For example:
Search: RegCloseKey
Result: https://learn.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regclosekey
Scroll down: Library Advapi32.lib

Alternatively, you can start a new VS project, copy paste the existing libraries over or just reconfigure SFML in the new project, without removing the other libraries.
Or you can use the SFML CMake template (https://github.com/SFML/cmake-sfml-project), then you don't really have to deal with library linking at all.