简体   繁体   中英

Cannot get FreeType library to work in Mac OS X Mountain Lion

I have an OpenGL project which works/compiles fine in Windows.
I wanted to port the application to Mac OS.
I got the application up and running on Mac, but the text inside the project is not visible.
So I decided to use a 3rd party library for text rendering in Mac, I came across FreeType, which has many advantages such as anti-aliasing and UNICODE support.

So, I downloaded the library on my Mac, './configure'd it, did 'make' and 'make install' as I would normally do.
Then in Xcode I set search paths for both include and library directories,

/usr/local/include and /usr/local/lib respectively.

Then I added 'other linker flags' in Xcode, freetype-configure --libs gave me following flags-
- L/usr/local/lib -lfreetype -lz -lbz2 , I added them in Xcode.

Now, whenever I include a freetype header there is no problem, but when I call any method from the freetype library, it gives me following linker error.

Xcode链接器错误

After looking up on google I found out that I have to set the build targets accordingly, I did that, now my application builds for i386 x86 the issue still persist.

I also tried following flags while configuring freetype ./ configure CC="gcc -arch i386" CXX="g++ -arch i386" which did not help either.

I am relatively new to Mac OS X/Unix environment, I have previously got freetype working on windows with VS 2008. Any help would be greatly appreciated.

What:

It seems you have more than one libfreetype.dylib file in your library search paths.

/master_repository/......../lib contains one and /usr/local/lib contains another

-lfreetype is a convenient way of telling the linker to look for file named libfreetype.dylib in all the directories specified with -L flags. Because -L/master_repository... comes before -L/usr/local/lib in the linker argument list, the linker uses the first instance it finds and attempts linking to that one.

Fix:

  • Reorganising your -L flags so that -L/usr/local/lib comes before the other. Avoid this option if you can.

  • Removing the extra search path, leaving only the relevant one.

  • Specifying the library explicitly instead of relying on the convenient -l by replacing -lfreetype with a full path to a library: /usr/local/lib/libfreetype.dylib

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM