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

Author Topic: Dynamic SFML doesn't link  (Read 892 times)

0 Members and 1 Guest are viewing this topic.

Gordem

  • Newbie
  • *
  • Posts: 4
    • View Profile
Dynamic SFML doesn't link
« on: January 02, 2023, 05:55:05 pm »
So dynamic SFML doesn't link, neither debug nor release, while static one does fine.
The errors for release mode:
Linking CXX shared library ..\..\..\lib\sfml-graphics-2.dll
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/C++/.libs/FreeType/freetype-2.12.1/mingw32-make/static/release/lib/libfreetype.a(sfnt.c.obj):sfnt.c:(.text+0x5e8b): undefined reference to `png_create_read_struct'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/C++/.libs/FreeType/freetype-2.12.1/mingw32-make/static/release/lib/libfreetype.a(sfnt.c.obj):sfnt.c:(.text+0x5ea0): undefined reference to `png_create_info_struct'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/C++/.libs/FreeType/freetype-2.12.1/mingw32-make/static/release/lib/libfreetype.a(sfnt.c.obj):sfnt.c:(.text+0x5ec3): undefined reference to `png_set_longjmp_fn'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/C++/.libs/FreeType/freetype-2.12.1/mingw32-make/static/release/lib/libfreetype.a(sfnt.c.obj):sfnt.c:(.text+0x5efe): undefined reference to `png_destroy_read_struct'
[...]
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/C++/.libs/FreeType/freetype-2.12.1/mingw32-make/static/release/lib/libfreetype.a(ftgzip.c.obj):ftgzip.c:(.text+0x8d9): undefined reference to `inflate'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/C++/.libs/FreeType/freetype-2.12.1/mingw32-make/static/release/lib/libfreetype.a(ftgzip.c.obj):ftgzip.c:(.text+0x8e8): undefined reference to `inflateEnd'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/C++/.libs/FreeType/freetype-2.12.1/mingw32-make/static/release/lib/libfreetype.a(ftgzip.c.obj):ftgzip.c:(.text+0x93a): undefined reference to `inflateEnd'
 
For debug mode:
Linking CXX shared library ..\..\..\lib\sfml-graphics-d-2.dll
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/C++/.libs/FreeType/freetype-2.12.1/mingw32-make/static/debug/lib/libfreetyped.a(sfnt.c.obj): in function `error_callback':
D:/C++/.libs/FreeType/freetype-2.12.1-source/src/sfnt/pngshim.c:199: undefined reference to `png_get_error_ptr'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/C++/.libs/FreeType/freetype-2.12.1-source/src/sfnt/pngshim.c:206: undefined reference to `png_set_longjmp_fn'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/C++/.libs/FreeType/freetype-2.12.1/mingw32-make/static/debug/lib/libfreetyped.a(sfnt.c.obj): in function `read_data_from_FT_Stream':
D:/C++/.libs/FreeType/freetype-2.12.1-source/src/sfnt/pngshim.c:230: undefined reference to `png_get_io_ptr'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/C++/.libs/FreeType/freetype-2.12.1-source/src/sfnt/pngshim.c:236: undefined reference to `png_get_error_ptr'
[...]
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/C++/.libs/FreeType/freetype-2.12.1/mingw32-make/static/debug/lib/libfreetyped.a(ftgzip.c.obj): in function `ft_gzip_file_fill_output':
D:/C++/.libs/FreeType/freetype-2.12.1-source/src/gzip/ftgzip.c:454: undefined reference to `inflate'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/C++/.libs/FreeType/freetype-2.12.1/mingw32-make/static/debug/lib/libfreetyped.a(ftgzip.c.obj): in function `FT_Gzip_Uncompress':
D:/C++/.libs/FreeType/freetype-2.12.1-source/src/gzip/ftgzip.c:765: undefined reference to `inflateInit2_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/C++/.libs/FreeType/freetype-2.12.1-source/src/gzip/ftgzip.c:770: undefined reference to `inflate'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/C++/.libs/FreeType/freetype-2.12.1-source/src/gzip/ftgzip.c:773: undefined reference to `inflateEnd'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/C++/.libs/FreeType/freetype-2.12.1-source/src/gzip/ftgzip.c:781: undefined reference to `inflateEnd'
 
It happens only if FREETYPE_INCLUDE_DIR_freetype2, FREETYPE_INCLUDE_DIR_ft2build and FREETYPE_LIBRARY are pointing to my self-built FreeType instead of to the bundled one, which I believe is more right than to use pre-compiled binaries, which can bang out incompatibilities or some other unpleasant things at unexpected point, don't they. SFML_USE_SYSTEM_DEPS is set to false all the time, if that matters.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Dynamic SFML doesn't link
« Reply #1 on: January 02, 2023, 06:14:41 pm »
You're probably using the WinLibs UCRT version, while the SFML dependencies have been build with MSVCRT. The two are not compatible, so I suggest you either rebuild SFML's dependencies or switch to the MSVCRT WinLibs version.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Gordem

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Dynamic SFML doesn't link
« Reply #2 on: January 04, 2023, 09:19:43 am »
Hmm. My Windows PATH variable points to C:\msys64\mingw64\bin, and MSYS2's documentation says that MINGW64 subsystem uses MSVCRT. I guess that means that I use MSVCRT and not UCRT.
And there is in fact another one problem: when shipping together in one project debug SFML binary and debug self-built FreeType binary, and the project uses fonts in some form, linker throws errors which seem to be identical to the output under “debug” in my initial post.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Dynamic SFML doesn't link
« Reply #3 on: January 04, 2023, 10:18:22 am »
Oh I missed that you're using MSYS2 and somehow also missed your comment regarding self-built FreeType.
That then just sounds like you didn't build FreeType correctly.

Looks like you built FreeType with support for libpng, but then don't link libpng.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Gordem

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Dynamic SFML doesn't link
« Reply #4 on: January 04, 2023, 06:08:11 pm »
Indeed. I was linking only SFML and FreeType.
So it seems that indirect dependencies, or dependencies of dependencies, must be linked too. I think I misunderstand something there. When I was building FreeType, I've configured it to use static libpng (also self-built). When I was building HarfBuzz, I've configured it to use static FreeType. And when I was building FreeType again, I've told it to use static HarfBuzz. And everywhere I've told everything to use static libraries, except for when building dynamic SFML (which did not link successfully anyway). Why must I still link the dependencies then? Why wasn't their code included into FreeType; isn't that the point of static libraries? Does the linker treat static libraries differently when linking a library vs an executable?
Adding HarfBuzz, HarfBuzz-free FreeType, libpng, Brotli, bzip2 and zlib did fix many errors, but there are still thirty-eight of them complaining about undefined references to HarfBuzz's objects in HarfBuzz's code and to Brotli's objects in Brotli's code. That is something even more strange.
But it's possible that these errors result from probably incorrectly built FreeType, so they are likely to fix when I rebuild FreeType correctly.
I still don't understand how linking a library with static dependencies works though.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Dynamic SFML doesn't link
« Reply #5 on: January 04, 2023, 06:52:31 pm »
If you build static libraries, they'll only contain their own symbols, but not the ones of the dependencies. When you build shared libraries the statically linked dependencies will be included in the shared library.
So any shared library or executable that links a static lib, will also have to link that static lib's dependencies.

It's the same with SFML. If you link SFML dynamically you don't have to specify freetype or vorbis, etc. But if you link SFML statically, you also have to specify all of SFML's dependencies.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Gordem

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Dynamic SFML doesn't link
« Reply #6 on: January 11, 2023, 04:55:19 pm »
I've added new CMake variables pointing to the indirect dependencies (zlib, bzip2, HarfBuzz, etc.,  but not to FreeType-without-HarfBuzz-hinting) to SFML configuration and set SFML_USE_SYSTEM_DEPS to true. Then rebuilt. Linker still reports about missing symbols from HarfBuzz, libpng, bzip2 ¿and gzip? used by FreeType, in both debug and release modes.
Сonfiguring dynamic release SFML with SFML_USE_SYSTEM_DEPS set to true hangs indefinitely, however that was so even before now.
What could be wrong with FreeType?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Dynamic SFML doesn't link
« Reply #7 on: January 11, 2023, 05:03:52 pm »
Make sure you re-run things with a clean configuration, so you don't accidentally use stuff that has been cached.

Best way to see what's going on, is to run CMake in verbose mode, so you see what commands are actually sent to the compiler and you can verify that the used libraries are really what you expect.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything