SFML community forums

Help => General => Topic started by: zjschrage on March 02, 2023, 02:24:32 am

Title: Statically Link SFML Libraries
Post by: zjschrage 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

Title: Re: Statically Link SFML Libraries
Post by: eXpl0it3r 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 (https://www.sfml-dev.org/tutorials/2.5/start-cb.php).

Also, your linking order is wrong. The rule of thumb (https://dev.my-gate.net/2018/01/10/rule-of-thumb-linking-order/) 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. ;)
Title: Re: Statically Link SFML Libraries
Post by: zjschrage 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)
Title: Re: Statically Link SFML Libraries
Post by: Hapax on March 18, 2023, 08:17:32 am
The dependencies are all listed in the Getting Started Tutorial (https://www.sfml-dev.org/tutorials/2.5/start-cb.php) (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 (https://www.sfml-dev.org/faq.php#build-link-static).