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

Author Topic: Statically Link SFML Libraries  (Read 3927 times)

0 Members and 1 Guest are viewing this topic.

zjschrage

  • Newbie
  • *
  • Posts: 2
    • View Profile
Statically Link SFML Libraries
« on: March 02, 2023, 02:24:32 am »
Hi,

PROBLEM:

I am trying to statically link my project so I can send it to my friend (dynamically linking works fine but I wont want to have to install sfml on their computer) but I am getting a symbol not defined linker error.

WHAT I HAVE DONE:

I created a folder called lib_sfml_static where i put 4 static libraries such as libsfml-system-s.a inside. I am using the following flags to indicate i want to do static linking:

-D SFML_STATIC -Llib_sfml_static -lsfml-system-s -lsfml-window-s -lsfml-audio-s -lsfml-graphics-s

I thought that the symbol not defined error means that I'm missing header files so I also tried copying the header files to another folder and adding another include directive -Isfml_static_headers but this seemed to not work, and I read online that I shouldn't actually have to specify headers with static libraries.

GITHUB

Here is the github link of the project, make snake-stat is the command that I run to make statically versus dynamically.

https://github.com/zjschrage/Snake/blob/main/src/Makefile


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Statically Link SFML Libraries
« Reply #1 on: March 02, 2023, 09:05:48 am »
Of course you still need header files when linking SFML statically.
When linking SFML statically, you also need to link all of SFML's dependencies, see the getting started tutorial.

Also, your linking order is wrong. The rule of thumb is, if X depends on Y, the X has to come before Y. Since sfml-graphics depends on sfml-window and sfml-system, those two need to come after the sfml-graphics library in the list.


Next time, please check in which sub forum you're posting. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

zjschrage

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Statically Link SFML Libraries
« Reply #2 on: March 02, 2023, 10:37:52 am »
Where can i find all those other dependencies, I found this:

https://github.com/SFML/SFML/tree/master/extlibs

but I cant find them all or i cant find the static ones here. I downloaded the current main static libraries somewhere online and it didn't have all this other stuff.

Thanks for the help  ;D

(also sorry about posting in the wrong place)

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Statically Link SFML Libraries
« Reply #3 on: March 18, 2023, 08:17:32 am »
The dependencies are all listed in the Getting Started Tutorial (as posted above by eXpl0it3r). Scroll to just after half-way (above the sample code) and you'll see a very large table of them (it has the header "Dependencies").

Another list of them are here, in the SFML FAQ about linking statically.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*