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

Author Topic: Why does this link chain not work (SFML static link)  (Read 1233 times)

0 Members and 1 Guest are viewing this topic.

Gamaray

  • Newbie
  • *
  • Posts: 6
    • View Profile
Why does this link chain not work (SFML static link)
« on: October 24, 2022, 05:22:58 pm »
I'm having issues statically linking a program on windows 10.
I have built SFML with cmake and now need to statically compile my code.
To do this I am using a Makefile that looks like this:

all:
    g++ main.cpp -o wampus.exe -DSFML_STATIC -I C:\lib\SFML\include -L C:\lib\SFML\lib -lsfml-window-s -
    lsfml-system-s -lopengl32 -lwinmm -lgdi32 -lsfml-graphics-s -lfreetype -lsfml-audio-s -lopenal -lflac
    -lvorbisenc -lvorbisfile -lvorbis -logg

When I run mingw32-make all,  I get a pretty massive chain of errors, presumably because this link chain is not in the correct order. It there a way I can fix this?

Error snippet:

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\lib\SFML\lib/libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp:(.text+0x890): undefined reference to `sf::FileInputStream::FileInputStream()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\lib\SFML\lib/libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp:(.text+0x89b): undefined reference to `sf::FileInputStream::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\lib\SFML\lib/libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp:(.text+0x8d3): undefined reference to `sf::FileInputStream::seek(long long)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\lib\SFML\lib/libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp:(.text+0x8ea): undefined reference to `sf::FileInputStream::~FileInputStream()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\lib\SFML\lib/libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp:(.text+0xa2d): undefined reference to `sf::FileInputStream::~FileInputStream()'
collect2.exe: error: ld returned 1 exit status
mingw32-make: *** [Makefile:2: all] Error 1

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Why does this link chain not work (SFML static link)
« Reply #1 on: October 24, 2022, 07:54:24 pm »
The link order is important.

Rule of Thumb is if X depends on Y, X has to come before Y.

The graphics module depends on the window module, so it needs to come before the graphics module.
The window module and audio modules depend on the system module, so they need to come before the system module.

Also see the full dependency list for MinGW on Windows here: https://www.sfml-dev.org/tutorials/2.5/start-cb.php
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Gamaray

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Why does this link chain not work (SFML static link)
« Reply #2 on: October 24, 2022, 09:40:13 pm »
Ah thanks so much.
I'm surprised I never came across that page you linked before now.

PawelSokolowski

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Why does this link chain not work (SFML static link)
« Reply #3 on: December 27, 2022, 06:37:00 pm »
I have  a problem with static linking and I just found this thread.
I added a preprocessor directive SFML_STATIC, and -s to all names of libraries.
Unfortunately I got lots of unresolved symbols.
When I removed the -s, it seems to be ok, except of 2 unresolved symbols sf::Color::White, and RenderStates::Default.
I am confused, preprocessor directive does not work ? Since the static libs are not linked properly, and when I switch back to dynamic libs, it is linking ok. Not exactly ok, because of 2 symbols that are unresolved.
One of them, sf::Color::White, I just replaced with sf::Color(255,255,255,255), and it's ok, but RenderStates::Default is still unresolved. Replacing it with a constant that I peek in headers would be a bit stupid. I wonder what's the reason that these symbols are undefined after adding preprocessor directive SFML_STATIC.
I have changed the order of libraries, but number of errors did not decrease, so the advice from above did not help.
Can anybody explain to me how to make properly static linking  ?

 

anything