msys2 / MINGW-packages

Package scripts for MinGW-w64 targets to build under MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
2.31k stars 1.23k forks source link

freetype2 pkg-config has wrong linking order #4004

Open RobertBColton opened 6 years ago

RobertBColton commented 6 years ago

I discovered this porting over part of a game engine's font packer from Linux to Win32.

With this in my makefile:

override LDLIBS += $(shell pkg-config --libs --static freetype2)

I receive these linking errors:

C:/msys64/mingw64/lib\libharfbuzz.a(libharfbuzz_la-hb-ft.o):(.text+0xf88): undefined reference to `FT_Get_MM_Var'
C:/msys64/mingw64/lib\libharfbuzz.a(libharfbuzz_la-hb-ft.o):(.text+0xff6): undefined reference to `FT_Get_Var_Blend_Coordinates'
C:/msys64/mingw64/lib\libharfbuzz.a(libharfbuzz_la-hb-ft.o):(.text+0x10f1): undefined reference to `FT_Done_MM_Var'
C:/msys64/mingw64/lib\libharfbuzz.a(libharfbuzz_la-hb-ft.o):(.text+0x1470): undefined reference to `FT_Set_Var_Blend_Coordinates'

The workaround I discovered is to specify -lfreetype a second time:

override LDLIBS += $(shell pkg-config --libs --static freetype2) -lfreetype

This is what I get running the pkg-config from the MSYS2 terminal:

Owner@Bedroom-Desktop MINGW64 /c/Users/Owner/Desktop/enigma-dev
$ pkg-config --libs --static freetype2
-LC:/msys64/mingw64/lib -lfreetype -lbz2 -lpng16 -lz -lharfbuzz -lm -lglib-2.0 -lintl -pthread -lws2_32 -lole32 -lwinmm -lshlwapi -lpcre -lintl -lpcre -lgraphite2

This makes my errors go away, and is an acceptable workaround for my own project, but I want to report it anyway because perhaps the order of the pkg-config libs should be switched around so others do not encounter this issue.

lazka commented 6 years ago

seems like harfbuzz is missing entries for freetype

Alexpux commented 6 years ago

@RobertBColton this is I think due to circular dependency between harfbuzz and freetype. I dont know any good workaround here

RobertBColton commented 6 years ago

I see, that is tricky, uhm, is it not maybe still a good idea to, you know, list the circular dependency in both package's configuration? My colleague/friend/expert on C++ has told me that the way I link freetype essentially twice is not any sort of size or performance concern, gcc should detect the duplicate linkage and reorder them accordingly. I'll attempt to dig up some references on this. But I am simply still suggesting that as it may make it easier for people to use the package out of the box.

Edit: I've discovered an alternative to linking it twice. https://stackoverflow.com/a/4813558

--start-group -LC:/msys64/mingw64/lib -lfreetype -lbz2 -lpng16 -lz -lharfbuzz -lm -lglib-2.0 -lintl -pthread -lws2_32 -lole32 -lwinmm -lshlwapi -lpcre -lintl -lpcre -lgraphite2 --end-group

Edit 2: My friend said the following in regards to my --start-group work around.

please don't do that unless you really have to that drives link times through the roof

so it's better to link twice?

yes

retostockli commented 4 years ago

How about compilling freetype without harfbuzz support? On Ubuntu libfreetype does not have harfbuzz functionality. Seems to work for those users.

RobertBColton commented 4 years ago

@retostockli what would be the consequences of that? I don't think our game engine project cares personally until it has some kind of an impact on how we use it to build the games or dynamically load ttfs at runtime.