PDA

View Full Version : Static linking freetype and FTGL


TomorrowPlusX
2004.10.13, 01:14 PM
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?

DoG
2004.10.13, 02:43 PM
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.

TomorrowPlusX
2004.10.13, 04:16 PM
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.

phydeaux
2004.10.13, 05:05 PM
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.

OneSadCookie
2004.10.13, 05:07 PM
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.

TomorrowPlusX
2004.10.13, 06:00 PM
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.

Thanks!