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

Author Topic: Static linking error (LNK2001 unresolved external symbol)  (Read 913 times)

0 Members and 1 Guest are viewing this topic.

Qubik

  • Newbie
  • *
  • Posts: 3
    • View Profile
Static linking error (LNK2001 unresolved external symbol)
« on: January 15, 2023, 05:01:20 pm »
When I try to compile my project with SFML_STATIC I get these errors:
  • LNK2001 unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default" (?Default@RenderStates@sf@@2V12@B)
  • LNK1120 1 unresolved externals

I don't get any errors when compiling with SFML_DYNAMIC.

I have followed the https://www.sfml-dev.org/tutorials/2.5/start-vc.php tutorial.
I have made another project (just for test) where I followed everything word for word, and it still didn't work with SFML_STATIC

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: Static linking error (LNK2001 unresolved external symbol)
« Reply #1 on: January 16, 2023, 01:01:08 pm »
SFML_DYNAMIC doesn't exist, so you don't need to specify it.
Read the tutorial again, if you use SFML_STATIC, you have to link SFML also statically (the libs with the -s suffix).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Qubik

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Static linking error (LNK2001 unresolved external symbol)
« Reply #2 on: January 21, 2023, 01:45:06 pm »
Yes, I have the ones with -s suffix, and it still doens't work.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: Static linking error (LNK2001 unresolved external symbol)
« Reply #3 on: January 21, 2023, 05:07:28 pm »
Make sure your configuration is defined for the matching architecture (x86vs x64) and config (debug vs release).
If you configured it for x64, but use x86 to build your application, the config won't be used.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Qubik

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Static linking error (LNK2001 unresolved external symbol)
« Reply #4 on: January 22, 2023, 08:01:05 pm »
Yes, as I said I followed the tutorial and did everything that was said there.

I have included the lib and include folders (didn't delete anything) and added them to the solution (as it was in the guide).
I have matching achitectures (x64 in my case) both for the solution and the SFML itself.
I have also added the dll's (both for release and debug with -d suffix) to the project (made sure to add them in linker in additional dependencies).
The code that I have is from the tutorial that I have sent earlier.

The erros that I get when compiling with SFML_STATIC:
  • Error LNK2001 unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default" (?Default@RenderStates@sf@@2V12@B)
  • Error LNK2001 unresolved external symbol "public: static class sf::Color const sf::Color::Green" (?Green@Color@sf@@2V12@B)
  • Error LNK1120 2 unresolved externals

The code does compile without any preprocessor definitions, I only get erros when I have the SFML_STATIC added.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: Static linking error (LNK2001 unresolved external symbol)
« Reply #5 on: January 22, 2023, 08:24:38 pm »
Then we just circle back to the original response, as these errors occur when you define SFML_STATIC, but don't link the static libraries.
Important, those are not in addition to other SFML libraries, but they are an instead-of replacement.
If you want to link SFML statically, you need to remove the existing sfml-graphics-d.lib or similar from your linker settings and replace them with sfml-graphics-s-d.lib or similar.

I have also added the dll's (both for release and debug with -d suffix) to the project (made sure to add them in linker in additional dependencies).
I hope you don't actually mean that you've added the *.dll files to the linker settings. You don't link *.dll files, but you link import (or static libraries), which have the *.lib extension for Visual Studio.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything