Getting the freetype library to load on other computers

Member
Posts: 509
Joined: 2002.05
Post: #1
After spending 5 hours trying to get my new project to run on other macs, I have to ask for help. I've learned a ton about how to build open source projects in the terminal and how to get libraries running on my computer, but I still can't make that last step.

When I try to launch my program on another computer without freetype installed I get this message -
Code:
Dyld Error Message:
  Library not loaded: /usr/local/lib/libfreetype.6.dylib

I've added libfreetype.6.dylib to my XCode project and even setup a copy phase to copy the .dylib file into my application bundle, is there anything else I need to do in XCode to get the program to search in the bundle for the .dylib file? I tried changing the Library Search Path to @executable_path/../, but that didn't help.

I tried static linking with the .a file before dynamic, but I was having problems with that too.

Thanks in advance for any suggestions
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
For FreeType, since the license permits static linking, there's probably no good reason to link dynamically. http://onesadcookie.com/svn/Third-Party/ builds a static library of freetype (and others) for each architecture supported by the Xcode SDKs you have. You can then either use lipo to fatten them into a universal static lib, or link to them directly as-is.

If you do want to link dynamically for some reason, http://blog.onesadcookie.com/2008/01/ins...magic.html explains how make the library bundleable with your application.

You almost certainly did not want to install freetype in /usr/local; that's likely to cause you problems later. You may want to consider removing /usr/local entirely, depending on what else you have in there.
Quote this message in a reply
Member
Posts: 509
Joined: 2002.05
Post: #3
Thanks for the link about dynamically linking, I was reading up on that stuff earlier today and was hoping it wouldn't be that complicated, but I guess it really is.

I have no idea how/why freetype keeps installing to /usr/local, but whenever I download the source freetype-2.3.7.tar and build it with

Code:
cd (to correct folder)
./configure
make
sudo make install

that is where it ends up. I've tried several different ./configure flags but I always end up with the same result. My libfreetype.a is 2.5MB, but I found one that came with the apple's 10.4u SDK that is 1.5MB, neither work.

I wasn't able to figure out how to get that makefile working from your svn site, until now I've always avoided that stuff in favor of a IDE with a GUI.

So I guess I'm confused on why both of my libfreetype.a files can compile and link without warnings, but when I try to run them on another computer the still look for that .dylib file.

Thanks
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
"sudo make install" is what's sticking it in /usr/local; you can change where it goes with ./configure --prefix=wherever; that's what my script does. There's no particular reason to run "make install" at all.

Code:
svn co http://onesadcookie.com/svn/Third-Party/
cd Third-Party
make

That is all.

The blog entry I linked you to explains why the compiled app looks where it does. Remember also that the linker will always choose a dynamic library over a static one (which is usually very unhelpful).
Quote this message in a reply
Member
Posts: 509
Joined: 2002.05
Post: #5
Wow, those three lines of code are awesome!

So I tried to uninstall by going through all the folders in usr/local/ and deleting things related to freetype. After this my project wouldn't build (couldn't find the right headers), so I moved all the necessary files from your third-party folder to where they needed to go. I also deleted my old libfreetype.a from my project and added the new one from third-party (I haven't bothered making it a UB yet, I'll mess with that after I get it running with intel).

I still get the "dyld: Library not loaded: /usr/local/lib/libfreetype.6.dylib" error. So is the linker trying to link the dynamic library instead of the static one, like you just mentioned? Does my computer still think there is a dynamic library somewhere on the computer because I didn't uninstall it right? How do I get XCode to link with the libfreetype.a file instead of looking for the .dylib?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
Yes, clearly it's still linking to a dylib from somewhere. Make sure you've cleaned since you changed the library.

You can force linking to a static library by passing /path/to/libfoo.a to the linker, rather than -lfoo. Xcode will do the latter if you just drag the library into the project; you can force the former by typing it explicitly in "other linker flags" rather than adding the library to the project. Generally, it's easier to ensure you don't have any dylibs you don't want Rasp
Quote this message in a reply
Member
Posts: 509
Joined: 2002.05
Post: #7
Oh I've cleaned this project about 50 times, my trash is filled with failed build folders.

I was able to add the the file to the other linker flags, and it got pretty close to linking, but I still get this -
Code:
...
/Users/jake/Third-Party/install/i386/lib/libfreetype.a
...
Undefined symbols:
  "_inflateInit2_", referenced from:
      _ft_gzip_file_init in libfreetype.a(ftgzip.o)
  "_inflate", referenced from:
      _ft_gzip_file_fill_output in libfreetype.a(ftgzip.o)
  "_inflateEnd", referenced from:
      _ft_gzip_file_done in libfreetype.a(ftgzip.o)
  "_inflateReset", referenced from:
      _ft_gzip_file_reset in libfreetype.a(ftgzip.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status

Googling the error brought up one or two similar problems, but they didn't really lead to an answer (one needed libgzip maybe?)
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #8
Adding -lz to your linker flags might fix the inflate errors.
Quote this message in a reply
Member
Posts: 509
Joined: 2002.05
Post: #9
ThemsAllTook Wrote:Adding -lz to your linker flags might fix the inflate errors.

That does the trick!

Thanks a ton for the help, I can't wait to post a demo of my new game sometime this summer. I've wanted to start a new game for years but haven't had the time, but now I'm able to get college credit for one of my required internships by working full-time this summer on Nuclearnova (not quite microelectronic engineering but I was able to convince them Smile)
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Cannot load NSData from NSUserDefaults groffhibbitz 1 3,678 Jun 25, 2009 10:25 PM
Last Post: SethWillits