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

Author Topic: [SOLVED] Static linking in MS VS2019  (Read 1233 times)

0 Members and 1 Guest are viewing this topic.

PawelSokolowski

  • Newbie
  • *
  • Posts: 3
    • View Profile
[SOLVED] Static linking in MS VS2019
« on: December 27, 2022, 07:56:06 pm »
Hi everyone,

I have read all threads about static linking, and nothing works.
I have added preprocessor directive SFML_STATIC
I have such libs included :
sfml-graphics-s.lib;
sfml-window-s.lib;
sfml-system-s.lib;
sfml-network-s.lib;
sfml-audio-s.lib;
kernel32.lib;
user32.lib;
gdi32.lib;
winspool.lib;
comdlg32.lib;
advapi32.lib;
shell32.lib;
ole32.lib;
oleaut32.lib;
uuid.lib;
odbc32.lib;
odbccp32.lib;
winmm.lib;
%(AdditionalDependencies)

and still I have errors:
Build started...
1>------ Build started: Project: Game1, Configuration: Release Win32 ------
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol _glFlush@0
1>sfml-graphics-s.lib(Shader.cpp.obj) : error LNK2001: unresolved external symbol _glFlush@0
1>sfml-graphics-s.lib(Shader.cpp.obj) : error LNK2001: unresolved external symbol _glGetIntegerv@8
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol _glGetIntegerv@8
1>sfml-graphics-s.lib(GLExtensions.cpp.obj) : error LNK2001: unresolved external symbol _glGetIntegerv@8
1>sfml-graphics-s.lib(TextureSaver.cpp.obj) : error LNK2001: unresolved external symbol _glGetIntegerv@8
1>sfml-graphics-s.lib(RenderTextureImplFBO.cpp.obj) : error LNK2001: unresolved external symbol _glGetIntegerv@8
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol _glGetTexImage@20
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol _glLoadIdentity@0
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glLoadIdentity@0
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol _glLoadMatrixf@4
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glLoadMatrixf@4
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol _glMatrixMode@4
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glMatrixMode@4
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol _glTexImage2D@36
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol _glTexParameteri@12
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol _glBindTexture@8
1>sfml-graphics-s.lib(TextureSaver.cpp.obj) : error LNK2001: unresolved external symbol _glBindTexture@8
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol _glCopyTexSubImage2D@32
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol _glDeleteTextures@8
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol _glGenTextures@8
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol _glTexSubImage2D@36
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_Init_FreeType
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_Done_FreeType
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_New_Face
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_New_Memory_Face
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_Open_Face
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_Done_Face
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_Set_Pixel_Sizes
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_Load_Char
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_Get_Kerning
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_Select_Charmap
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_Get_Char_Index
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_MulFix
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_Get_Glyph
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_Glyph_To_Bitmap
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_Done_Glyph
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_Outline_Embolden
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_Bitmap_Embolden
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_Stroker_New
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_Stroker_Set
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_Stroker_Done
1>sfml-graphics-s.lib(Font.cpp.obj) : error LNK2001: unresolved external symbol _FT_Glyph_Stroke
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glBlendFunc@8
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glClear@4
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glClearColor@16
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glDisable@4
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glEnable@4
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glPopAttrib@0
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glPopMatrix@0
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glPushAttrib@4
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glPushMatrix@0
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glViewport@16
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glColorPointer@16
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glDisableClientState@4
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glDrawArrays@12
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glEnableClientState@4
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glPopClientAttrib@0
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glPushClientAttrib@4
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glTexCoordPointer@16
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol _glVertexPointer@16
1>sfml-graphics-s.lib(GLExtensions.cpp.obj) : error LNK2001: unresolved external symbol _glGetError@0
1>sfml-graphics-s.lib(GLExtensions.cpp.obj) : error LNK2001: unresolved external symbol _glGetString@4
1>sfml-window-s.lib(GlContext.cpp.obj) : error LNK2001: unresolved external symbol __imp__glEnable@4
1>sfml-window-s.lib(GlContext.cpp.obj) : error LNK2001: unresolved external symbol __imp__glGetError@0
1>sfml-window-s.lib(GlContext.cpp.obj) : error LNK2001: unresolved external symbol __imp__glGetIntegerv@8
1>sfml-window-s.lib(GlContext.cpp.obj) : error LNK2001: unresolved external symbol __imp__glGetString@4
1>sfml-window-s.lib(GlContext.cpp.obj) : error LNK2001: unresolved external symbol __imp__glIsEnabled@4
1>sfml-window-s.lib(WglContext.cpp.obj) : error LNK2001: unresolved external symbol __imp__wglCreateContext@4
1>sfml-window-s.lib(WglContext.cpp.obj) : error LNK2001: unresolved external symbol __imp__wglDeleteContext@4
1>sfml-window-s.lib(WglContext.cpp.obj) : error LNK2001: unresolved external symbol __imp__wglGetProcAddress@4
1>sfml-window-s.lib(WglContext.cpp.obj) : error LNK2001: unresolved external symbol __imp__wglMakeCurrent@8
1>sfml-window-s.lib(WglContext.cpp.obj) : error LNK2001: unresolved external symbol __imp__wglShareLists@8
1>D:\_GAMEDEV\WARCABY\Release\Game1.exe : fatal error LNK1120: 64 unresolved externals
1>Done building project "Game1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Funny thing is, that if I include libs without -s, there are no errors about libs, but there is one:
Build started...
1>------ Build started: Project: Game1, Configuration: Release Win32 ------
1>Game1.obj : error LNK2001: unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default" (?Default@RenderStates@sf@@2V12@B)
1>D:\_GAMEDEV\WARCABY\Release\Game1.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "Game1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Can anyone have a look and explain what is going on ?

Regards

« Last Edit: December 27, 2022, 08:28:12 pm by PawelSokolowski »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Static linking in MS VS2019
« Reply #1 on: December 27, 2022, 08:06:39 pm »
Have you also added the path to the SFML headers (the include folder)?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

PawelSokolowski

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Static linking in MS VS2019
« Reply #2 on: December 27, 2022, 08:27:51 pm »
Have you also added the path to the SFML headers (the include folder)?

[SOLVED]

Thank you for your response.
I have included headers, before I decided to go STATIC, everything worked just fine. Without headers it would not compile dynamically as well.

I have just located the problem.
Apparently static linking does not include by default some additional system libraries that are needed.
I had to add OPENGL32.LIB and FREETYPE.LIB.
Strangely dynamic linking worked without it.




kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: [SOLVED] Static linking in MS VS2019
« Reply #3 on: December 27, 2022, 10:40:15 pm »
When a static library like sfml-graphics-s.lib is built, the full linking process isn't performed. It takes the compiled obj files and bundles them together. The dependencies of sfml-graphics-s.lib (like opengl32.lib) aren't included.
So adding a static library to your project is like adding all of the cpp files, except the compiling bit is already done. The final link step to make the executable still needs to be told about the dependencies.

A dynamic library has complete working code in the dll, it had the full link process so its dependencies were used. Adding the dynamic library to your project doesn't require libraries like opengl32.lib unless you wanted to access it directly yourself.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: [SOLVED] Static linking in MS VS2019
« Reply #4 on: December 28, 2022, 05:48:50 pm »
Ah, yes; I hadn't realised you had missed a couple of dependencies.

There is a complete list in the SFML FAQ, here:
https://www.sfml-dev.org/faq.php#build-link-static
as well as in the build tutorial:
https://www.sfml-dev.org/tutorials/2.5/start-vc.php#creating-and-configuring-a-sfml-project
« Last Edit: December 28, 2022, 05:50:51 pm by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*