SFML community forums

Help => General => Topic started by: Qubik on January 15, 2023, 05:01:20 pm

Title: Static linking error (LNK2001 unresolved external symbol)
Post by: Qubik on January 15, 2023, 05:01:20 pm
When I try to compile my project with SFML_STATIC I get these errors:

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 (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
Title: Re: Static linking error (LNK2001 unresolved external symbol)
Post by: eXpl0it3r 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).
Title: Re: Static linking error (LNK2001 unresolved external symbol)
Post by: Qubik on January 21, 2023, 01:45:06 pm
Yes, I have the ones with -s suffix, and it still doens't work.
Title: Re: Static linking error (LNK2001 unresolved external symbol)
Post by: eXpl0it3r 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.
Title: Re: Static linking error (LNK2001 unresolved external symbol)
Post by: Qubik 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:

The code does compile without any preprocessor definitions, I only get erros when I have the SFML_STATIC added.
Title: Re: Static linking error (LNK2001 unresolved external symbol)
Post by: eXpl0it3r 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.