I’m going to write a post about coding your own games from scratch later: it’s a topic I have quite strong feelings on (both ways), however right now I feel a pressing need to share with the world a fix for issues with CMake and a certain library that is widely used – FreeType 2.
FT2 is the way to load fonts, most definitely on Linux. Everyone uses it, from your off-hours gamedev such as me to the biggest engine devs such as Epic for Unreal. And if you’re using CMake to compile your code, it’s also one of the biggest pains in the arse you can have as well. These two lines of code:
#include <ft2build.h>
#include FT_FREETYPE_H
can cause a surprising amount of misery, as although CMake will find FreeType, when you compile you’ll get a nasty surprise as your makefile can’t find the necessary header files and proceeds to shit the bed with nasty compiler errors up the wazoo. (And the carnage doesn’t stop there, I had to google HTML code for the brackets surrounding it in the code sample above…).
So in my off-hours dev adventures, I’ve been building a game from scratch. This is only for if you are a sadomasochist who likes to rage against the compiler and you REALLY SHOULD USE UNITY, but sometimes I need my rage fix, and well… I came up against the wonders of the FreeType 2 header issue. Like I said, the compiler swore blind it couldn’t find ft2build.h
, or the inner workings of freetype2/freetype/config
. This was frustrating.
After much googling (and some choice words aimed at Clang), I was able to resolve the issue. And so, dear fellow FT2 sufferer, I provide you with my solution, the road to happiness. There are a few caveats: I’m a Linux developer (sorry Windows fans) using Ubuntu 16.04 (your distro may do things differently), and it only works with /usr, not /usr/local. My solution may only work for some, and not all Linuxes as they may place things elsewhere.
So without further ado:
sudo ln -s /usr/include/freetype2/ft2build.h /usr/include/
sudo ln -s /usr/include/freetype2/freetype /usr/include/freetype
And with those two lines, symbolically linking the necessary files, I found the road to happiness. The header files were found, and my code compiled perfectly. I sat back, and watched my freshly compiled binary load. It may have been a hack, but it’s a hack that put an end to a very frustrating issue for me.
So if you’re suffering FreeType 2 pains, dear reader, I hope this post can ease them. See you on the road to FreeType 2 happiness!