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

Author Topic: [SOLVED] Can't Compile With Static libs.  (Read 2591 times)

0 Members and 1 Guest are viewing this topic.

tom42

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
[SOLVED] Can't Compile With Static libs.
« on: January 22, 2021, 12:37:39 pm »
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.
« Last Edit: January 30, 2021, 01:10:42 pm by tom42 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11035
    • View Profile
    • development blog
    • Email
Re: Cant Compile With Static libs.
« Reply #1 on: January 22, 2021, 03:22:07 pm »
The order you link libraries in is important for ld.

My rule of thumb 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

tom42

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Cant Compile With Static libs.
« Reply #2 on: January 22, 2021, 03:42:38 pm »
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 and put Dependencies before static modules that requires it?
« Last Edit: January 22, 2021, 03:55:53 pm by tom42 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11035
    • View Profile
    • development blog
    • Email
Re: Cant Compile With Static libs.
« Reply #3 on: January 22, 2021, 04:07:24 pm »
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?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

tom42

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Cant Compile With Static libs.
« Reply #4 on: January 22, 2021, 04:10:36 pm »
...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.
« Last Edit: January 22, 2021, 04:15:15 pm by tom42 »

tom42

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Cant Compile With Static libs.
« Reply #5 on: January 30, 2021, 01:08:49 pm »
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.

 

anything