Static linking freetype and FTGL

Posts: 1,199
Joined: 2004.10
Post: #1
I recently started to use FTGL to display nice truetype for a HUD for my game.

FTGL itself works great. It looks good, performance is excellent, no problem.

The trouble is getting Xcode to statically link against the libs, so that the app is self-contained, and doesn't require users to install freetype!

I doscovered recently that Xcode was dynamically linking against libfreetype.dylib even though I had provided it with libfreetype.a

So, to fix this, my process was this: I built freetype on the command line but didn't install it -- so no headers or libs in /usr/local; and then rebuilt FTGL using the Xcode project, linking against the libfreetype.a in the freetype build folder.

libftgl built and linked, fine.

So then I built my app using it, and got this linker error:

ld: lib//libfreetype.a(ftgzip.o) illegal reference to symbol: _inflateEnd defined in indirectly referenced dynamic library /usr/lib/libz.1.dylib

Any ideas? What can I do?
Quote this message in a reply
Posts: 869
Joined: 2003.01
Post: #2
You could just include the dylib with the application bundle, afaik.

Your error is a link error, you should probably link with libz.dylib though.
Quote this message in a reply
Posts: 1,199
Joined: 2004.10
Post: #3
It seems peculiar to me, though, since libz.dylib exists in the standard Mac OS X install, in /usr/local.

What also seems odd is that when I was dynamically linking against libfreetype.dylib, I didn't get this linker error.
Quote this message in a reply
Posts: 184
Joined: 2004.07
Post: #4
I'm not sure how you do this in XCode, but you should be able to fix this problem by adding -lz to the linking line.

I would personally include a static build of libz as well since it's a really small library. Though I think every version of X has it.
Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #5
every version of Mac OS X has libz. Just add /usr/lib/libz.dylib to your project and all will be fine.

dylibs can link to libraries themselves, which is why you didn't get it before. "static libraries" are really just collections of object files, so you have to link to their dependencies yourself.
Quote this message in a reply
Posts: 1,199
Joined: 2004.10
Post: #6
Well, I already had /usr/lib/libz.dylib in my test project, but adding -lz did it! And a quick look at the output of otool tells me I'm set -- no dependencies outside of standard OS X libs and frameworks.

Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  How do I flip upside down fonts in FTGL mr5z 4 6,098 Mar 3, 2014 03:36 PM
Last Post: JustinFic
  Xcode and FTGL hiddenspring81 7 13,500 Oct 10, 2013 03:00 PM
Last Post: ardowz
  Anyone run into this problem with FTGL? wadesworld 1 4,668 Apr 21, 2009 02:19 PM
Last Post: Oddity007
  FTGL crash when exiting program Malarkey 8 9,903 Mar 27, 2008 03:33 PM
Last Post: Malarkey
  More Freetype/FTGL trouble Fenris 33 28,930 Sep 15, 2006 06:27 AM
Last Post: TomorrowPlusX