SFML community forums
Help => Graphics => Topic started by: intweek on May 30, 2023, 09:31:18 pm
-
Hello everyone,
I tried using sf::Text (or any other text related thing), but whenever I do so, I get a lot of errors, which all look like:
"Font.cpp:(.text+0x3178): undefined reference to `FT_Get_Char_Index"
What am I doing wrong?
NOTE: I am using VS code, windows 11, SFML is staticaly linked.
-
https://github.com/SFML/SFML#community
If you come over to the Discord server you can get some help on this. There's a number of potential reasons you have linker errors
-
The linker error tells FreeType is not linked.
If you link SFML statically, then you need to link its dependencies too. FreeType is one of the dependencies.
See the list of dependencies for each SFML module here: https://www.sfml-dev.org/faq.php#build-link-static
They are also listed in this tutorial: https://www.sfml-dev.org/tutorials/2.5/start-vc.php
-
The linker error tells FreeType is not linked.
If you link SFML statically, then you need to link its dependencies too. FreeType is one of the dependencies.
See the list of dependencies for each SFML module here: https://www.sfml-dev.org/faq.php#build-link-static
They are also listed in this tutorial: https://www.sfml-dev.org/tutorials/2.5/start-vc.php
So if I linked dynamically, I wouldn't need to do anything regarding downloading/linking freetype?
The question becomes, should I even link staticaly?
-
If linking dynamically, you don't need to manually link freetype, no.
You shouldn't need to download them either way; they're provided alongside SFML in SFML/extlibs (https://github.com/SFML/SFML/tree/master/extlibs).
Whether you should or not is a matter of taste/style, productivity and portability.
With dynamic linking you need to ship the (very few) SFML files with your executable. This is the easiest way, I'd say.
With static linking, the SFML stuff is stuffed inside your executable making it a fewer files, possibly reducing the number of files in your app by about 5.. :-X
But, with static linking, there are extra things you need to link and setup (defining SFML_STATIC, for example) so can cause some confusion sometimes.
Also, if you use the audio module, the OpenAL file must be shipped with your app regardless of whether it is dynamic or static.
If you're going to be providing one library file, why not (up to) 6 more ;D?
-
Space can be a factor too.
When a static library is linked, the linker can see which parts are being used, so it only merges those into your final executable.
When a dynamic library is linked, the linker doesn't know who will load it at runtime, so it must include everything.
This means a static link results in a slightly bigger executable than dynamic, but no dlls with unneeded stuff, so overall static will be smaller.
On the other hand, if you have several executables in your project (maybe a game, an editor, a config program, etc) that all use the same library, static linking means every one of them has to include the parts they need, while dynamic linking lets them all share the same dll. So dynamic might have a saving there.