Simutrans Forum Archive
A complete record of the old Simutrans Forum.

[r8764] Freetype build broken on Ubuntu

Started by ceeac, May 30, 2019, 06:34:39 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


OS: Ubuntu 19.04

Simutrans cannot be compiled with USE_FREETYPE=1 on Ubuntu because ft2build.h is not found. This is especially visible when building using autoconf because it enables USE_FREETYPE by default when freetype is installed.
The relevant header, however, is installed:

$ find /usr/include/ | grep ft2build

So it is probably a matter of looking in /usr/include/ vs. looking in /usr/include/freetype2/ .


Quote from: ceeac on May 30, 2019, 06:34:39 AM
So it is probably a matter of looking in /usr/include/ vs. looking in /usr/include/freetype2/ .

Simutrans uses freetype-config to get the paramter(s) needed to locate freetype.


Problem here is that Ubuntu seems to have dropped "freetype-config" when moving from "libfreetype6-dev 2.8" to libfreetype6-dev 2.9", so it is not available anymore on up-to-date Ubuntu installs.

Luckily "freetype-config" acts as a wrapper when "pkg-config" is available on the system (which should be on Ubuntu).

Hence you can work around this by making the following change to config.default

#FREETYPE_CONFIG = freetype-config                                                                     
FREETYPE_CONFIG = pkg-config freetype2 


Does this is somehow detected by autoconf. Otherwise I expect a lot of other software will be "broken" too ...


I'm not really knowledgeable enough about autoconf to be absolute certain but test seem to indicate it does.

The test performed (on a system without `freetype-config`):
* Using a pristine repository copy (no manual alterations [1])
* Run `autoconf` -> output message includes: "checking for library containing FT_Init_FreeType... -lfreetype"
* Run `./configure` -> Verified `configure.default` includes: "USE_FREETYPE = 1"
* Run `make`

This creates a working binary, with only one catch. In order to compile successfully i had to edit the Makefile (line 14)
FREETYPE_CONFIG ?= freetype-config
FREETYPE_CONFIG ?= pkg-config freetype2

As for the breakage of other software. This will most likely be the case for all distributions that do not take special precautions when building freetype2 (e.g. using the flag '--enable-freetype-config' for versions >= 2.9.1).
More information:
* The reason why the developers of freetype2 dropped it (for default builds) is mentioned in this bugreport
* They also warn against it's usage in one of their basic tutorials (last sentence of the first step).

Hope this helps a bit

[1] With the exception of the Makefile edit


On my Linux box, both freetype-config and pkg-config freetype2 works. On MSYS2, only freetype-config works. Since it is apparently possible to get new versions to work the old way, but not to get old versions to work the new way, it is probably best for Simutrans to stick with the legacy as default for now. Maybe it is possible for the Makefile to try both, but I don't know enough Makefile to know how to do that.


The old one is still used. However, one can add the line

FREETYPE_CONFIG = pkg-config freetype2
to config.default to use the new method.


I am trying to compile Simutrans-Extended with Freetype on Ubuntu 20.04. It appears that the relevant script (in config.template and the Makefile) is identical in Standard and Extended, and I have exactly the issue described in the thread title (apart from the revision number), so I have continued this thread.

When I enable USE_FREETYPE = 1 in config.default (with or without FREETYPE_CONFIG = freetype-config), I get this error message:
expr: syntax error: unexpected argument '1'Two of the top Google hits for that error message are to posts on this forum which suggest that the problem is caused by pkg-config not working correctly.

Looking in the Makefile leads me to think that this line is not working correctly:
FREETYPE_CONFIG  ?= pkg-config freetype2
This seems to have a simple explanation: I don't have a freetype2 package on my system. It seems that Ubuntu (following Debian) calls the packages for the Freetype 2 shared libraries libfreetype6 and the development files libfreetype-dev.

A search on Repology suggests that freetype2 is a package name mainly used by Arch, OpenSUSE, and their derivatives.

I am learning new things here, so it's very possible that I have misunderstood something. But my initial conclusion is that the Simutrans Makefile expects a package name that is only used on two families of distros, so compilation with Freetype is likely to fail on the Debian family of distros (and probably others).

When I get time to continue this project, I will try out pkg-config with the Ubuntu package names, but this is what I have discovered (or misunderstood!) so far. If anyone can see any flaws in my diagnosis, please do point them out.
(Signature being tested) If you enjoy playing Simutrans, then you might also enjoy watching Japan Railway Journal
Available in English and simplified Chinese


"pkg-config freetype2" is correct.
  File list of package libfreetype-dev in focal of architecture amd64:


TurfIt, thank you for explaining that the pkg-config is correct and for 'showing your working' so I can check this in future — that's really useful!

With help from Roboron over on Discord, I have realized that the underlying issue is in Extended's configure.* files, so I will create a separate thread for that in the right forum. And I now have FreeType working, yay!
(Signature being tested) If you enjoy playing Simutrans, then you might also enjoy watching Japan Railway Journal
Available in English and simplified Chinese