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

Author Topic: SFML Setup with Visual Studio  (Read 4468 times)

0 Members and 1 Guest are viewing this topic.

stikykees

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
SFML Setup with Visual Studio
« on: April 27, 2021, 10:54:37 pm »
Hello,

I have recently started using SFML for some projects to get practice with C++. I am using Visual Studio to run my program but sometimes get stuck while setting up SFML libraries.

Currently my release configuration runs the tutorial code perfectly however, the debug configuration gives 53 LNK errors of either 2019 or 2001. (I added the -d to the 4 main SFML libraries in debug config that I am using).

I am using Visual Studio 2019, SFML 2.5.1, C++, static SFML libraries.

Again, release configuration complies fine, debug config fails where all config settings are the same except the
-d added to the 4 main SFML libraries I'm using.


One of the 53 LNK errors
1>sfml-window-s-d.lib(InputImpl.cpp.obj) : error LNK2019: unresolved external symbol...

Debug dependencies:
(click to show/hide)


Edit (Solution):
Checking the "Inherit from parent or project defaults" in the Linker>>Input>>Add'l Dependencies fixed the problem. For some reason this happened by default in my debug configuration but not my release configuration.
« Last Edit: April 29, 2021, 06:59:30 am by stikykees »

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: SFML Setup with Visual Studio
« Reply #1 on: April 27, 2021, 11:16:37 pm »
It sounds like you have SFML_STATIC defined for release builds, but not for debug builds.
Go into project properties / C++ / Preprocessor / Preprocessor Definitions and make sure SFML_STATIC is there for debug builds.

stikykees

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: SFML Setup with Visual Studio
« Reply #2 on: April 28, 2021, 04:54:03 am »
It sounds like you have SFML_STATIC defined for release builds, but not for debug builds.
Go into project properties / C++ / Preprocessor / Preprocessor Definitions and make sure SFML_STATIC is there for debug builds.

Unfortunately, this is not the problem, I just double-checked it is defined. Very weird because I'm comparing all my settings to another project that functions and they are identical except adding the audio library to no avail.

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: SFML Setup with Visual Studio
« Reply #3 on: April 28, 2021, 07:15:13 am »
I tried breaking one of my older projects (I haven't used static sfml for a while) to see the errors it gave, it's probably not the static thing as I said previously. When the static flag is missing, the files on the left of the linker error line would be your files. But in this case it's sfml's window library on the left, so that means sfml is trying to find something (in another library?) that's missing.

But I can't see what it's looking for, could you post a complete linker error line? The bit you posted doesn't show the part of the error message that says what is missing.
(Preferably a few (or all) of the errors, in case there's a few different things missing)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: SFML Setup with Visual Studio
« Reply #4 on: April 28, 2021, 07:59:27 am »
You should always provide complete error messages.
While it might not seem useful to you, the error message does in fact tell you what is missing and then you can add it.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

stikykees

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: SFML Setup with Visual Studio
« Reply #5 on: April 28, 2021, 11:30:22 pm »
Complete error message list:
(click to show/hide)

Code if it is relevant (just testing window and audio functionality):
(click to show/hide)

Seeing as though all error messages begin with "1>sfml-window-s-d.lib" I recopied this file from the download into the SFML directory. The error messages were identical after making this change.
« Last Edit: April 28, 2021, 11:32:35 pm by stikykees »

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: SFML Setup with Visual Studio
« Reply #6 on: April 29, 2021, 03:39:57 am »
Ok, getting close now.
If we look at the first error:
sfml-window-s-d.lib(InputImpl.cpp.obj) : error LNK2019: unresolved external symbol __imp__GetAsyncKeyState@4 referenced in function "public: static bool __cdecl sf::priv::InputImpl::isKeyPressed(enum sf::Keyboard::Key)" (?isKeyPressed@InputImpl@priv@sf@@SA_NW4Key@Keyboard@3@@Z)

It's saying that the isKeyPressed function in sfml-windows-s-d can't find a function called __imp__GetAsyncKeyState@4.
GetAsyncKeyState is a windows sdk function. Checking it at https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getasynckeystate says it comes in user32.lib.
All the following errors look like they are user32.lib (or similar windows sdk lib) related too.

So for some reason your project isn't linking user32.lib. Usually it should be inherited in the linker settings:


My first guess would be your project is trying to use the wrong windows sdk.
Try right clicking on the project in the solution explorer and selecting Retarget Projects. Then choose one of the SDKs in the combo box and hit Ok.

stikykees

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: SFML Setup with Visual Studio
« Reply #7 on: April 29, 2021, 06:55:08 am »
Ok, getting close now.
If we look at the first error:
sfml-window-s-d.lib(InputImpl.cpp.obj) : error LNK2019: unresolved external symbol __imp__GetAsyncKeyState@4 referenced in function "public: static bool __cdecl sf::priv::InputImpl::isKeyPressed(enum sf::Keyboard::Key)" (?isKeyPressed@InputImpl@priv@sf@@SA_NW4Key@Keyboard@3@@Z)

It's saying that the isKeyPressed function in sfml-windows-s-d can't find a function called __imp__GetAsyncKeyState@4.
GetAsyncKeyState is a windows sdk function. Checking it at https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getasynckeystate says it comes in user32.lib.
All the following errors look like they are user32.lib (or similar windows sdk lib) related too.

So for some reason your project isn't linking user32.lib. Usually it should be inherited in the linker settings:


My first guess would be your project is trying to use the wrong windows sdk.
Try right clicking on the project in the solution explorer and selecting Retarget Projects. Then choose one of the SDKs in the combo box and hit Ok.


My only available windows SDK was 10.0 (latest version) but I noticed that "Inherit from parent or project defaults was unchecked while it was it was on your screenshot. Checking it ended up fixing the problem. Thank you so much for the help working through this. I would've never gotten it otherwise. ;D

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: SFML Setup with Visual Studio
« Reply #8 on: April 29, 2021, 12:46:56 pm »
Awesome! :)

 

anything