Linking Freetype library to Xcode project
Asked Answered
P

2

5

I'm having trouble using the Freetype library in my Xcode project and have the include at the top of my code #include <ft2build.h> ; however when I build the code, I get the error 'Ft2build.h' No Such file or directory. I had linked the library 'libfreetype.dylib' and included the following in 'Other Link Flags' in the Build tab: '-l/usr/local/include/freetype2/'.

I'm quite new to Xcode, and would appreciate any help here from someone that could highlight what I've missed.

Many thanks, Alex

Payday answered 21/9, 2015 at 13:6 Comment(4)
That's a compiler error, not a linker error.Spallation
@Spallation Hi thanks for the clarification of the nature of the error; would you know why I'm getting the compile error?Payday
Does ft2build.h exist in /usr/include (or some other include directory)?Spallation
@Spallation Hi that exists in: /usr/local/include/freetype2Payday
S
4

The issue is that you are putting (the necessary) -I/usr/local/include/freetype2 flags in Other Linker Flags and the linker doesn't care about include files.

Instead modify the Header Search Path in the Build Settings.

You will probably also need to modify the Library Search Path as well, in order to pickup the library.

Avoid using Other Linker Flags if you can help it.

Spallation answered 21/9, 2015 at 14:17 Comment(1)
Many thanks for your help, that's fixed the issue; learning a bit more each time I use Xcode. Best regards, AlexPayday
L
3

To link with freetype2 on macOS in XCode, determine the header/lib paths by running the following two commands in the terminal:

freetype-config --cflags    // example output: -I/opt/X11/include/freetype2
freetype-config --libs      // example output: -L/opt/X11/lib -lfreetype

... and change the Xcode project-setting accordingly:

"Header Search Paths"   => /opt/X11/include/freetype2
"Library Search Paths"  => /opt/X11/lib
"Other Linker Flags"    => -lfreetype
Lachman answered 4/3, 2017 at 19:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.