-
Hello everyone.
I'm trying to compile my silly hello-world SFML project for test. But getting strange error messages from linker. (When I compile with shared lib's - everything is OK.)
Also left this question & details here -> https://stackoverflow.com/questions/65830743/sfml-compilation-with-static-libs-error-c
Full error message is here. https://anotepad.com/notes/b34xbc2s
I don't know what to do\read\learn about this, newer build anything with static libs before. I'm clearly doing something stupid here.
-
The order you link libraries in is important for ld.
My rule of thumb (https://dev.my-gate.net/2018/01/10/rule-of-thumb-linking-order/) is "if X depends on Y, then X needs to come before Y"
Which would mean for example, that sfml-system needs to come after sfml-graphics and sfml-window and gl (OpenGL) needs to come after the sfml-window as well.
-
Thank you. But how can I know what depends on what?
When I change the order, I get this:
g++ -DSFML_STATIC -O2 -no-pie -fno-pie -I/home/uzzer/LIB/SFML-2.5.1/include -o main main.cpp -L/home/uzzer/LIB/SFML-2.5.1/lib -L/usr/lib/x86_64-linux-gnu -lsfml-graphics-s -lsfml-system-s -lsfml-window-s -lstdc++ -lc -lm -ldl -ludev -lX11 -lglfw -lGL -lGLU
/usr/bin/ld: /home/uzzer/LIB/SFML-2.5.1/lib/libsfml-system-s.a(MutexImpl.cpp.o): undefined reference to symbol 'pthread_mutexattr_settype@@GLIBC_2.2.5'
/usr/bin/ld: /lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
So, I need to use this https://www.sfml-dev.org/tutorials/2.4/start-vc.php (https://www.sfml-dev.org/tutorials/2.4/start-vc.php) and put Dependencies before static modules that requires it?
-
sfml-window depends on sfml-system so it should come after.
For other libraries you could potentially see it in the package manager somehow.
Or mostly just try things out.
What are you linking SFML and GLFW?
-
...I thought SFML needs GLFW, so I added it.
g++ -DSFML_STATIC -O2 -no-pie -fno-pie -I/home/uzzer/LIB/SFML-2.5.1/include -o main main.cpp -L/home/uzzer/LIB/SFML-2.5.1/lib -L/usr/lib/x86_64-linux-gnu -pthread -ludev -lX11 -lsfml-graphics-s -lsfml-system-s -lsfml-window-s -lGL -lGLU -lstdc++ -lc -lm -ldl
/usr/bin/ld: /home/uzzer/LIB/SFML-2.5.1/lib/libsfml-window-s.a(ClipboardImpl.cpp.o): undefined reference to symbol 'XConvertSelection'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libX11.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
... my head hurts.
-
I managed to figure it out. Thanks everyone! :)
This worked:
g++ -std=c++20 -DSFML_STATIC -O2 -no-pie -fno-pie -I/home/uzzer/LIB/SFML-2.5.1/include -o main main.cpp -L/home/uzzer/LIB/SFML-2.5.1/lib -L/usr/lib/x86_64-linux-gnu -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lGLU -lGL -lX11 -lXrandr -ludev -lpthread
*a bit confusing nonetheless.