The point is your app depends on the sfml-graphics framework, that depends on freetype. And sfml-graphics.framework has hardcoded the path where it should find freetype (ie. in the X11 directory).
If A is your application and B is your dependency:
The install name of B is where A (that is linked against B) should look to find B. When linking an application, the linker gathers the install name of the dependencies and hardcode them in the application.
Thus there are two possibilities:
- either modify the freetype dylib so that it provides a new relative install name, and relink sfml-graphics.framework. When relinking, the sfml-graphics framework will hardcode the new install name. That way, the sfml-graphics will no more look for freetype in the X11 directory.
- or just modify the path of the freetype dependency in the sfml-graphics framework.
I'll stick with the second solution as it's more straightforward. First, make a copy of sfml-graphics.framework. In a Terminal, go IN this copy, then...
ls
should give this:
Resources Versions sfml-graphics
otool -L sfml-graphics
should give this:
sfml-graphics:
@executable_path/../Frameworks/sfml-graphics.framework/Versions/2.0.0/sfml-graphics (compatibility version 2.0.0, current version 2.0.0)
@executable_path/../Frameworks/sfml-window.framework/Versions/2.0.0/sfml-window (compatibility version 2.0.0, current version 2.0.0)
@executable_path/../Frameworks/sfml-system.framework/Versions/2.0.0/sfml-system (compatibility version 2.0.0, current version 2.0.0)
/usr/X11/lib/libfreetype.6.dylib (compatibility version 14.0.0, current version 14.2.0)
/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 833.25.0)
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1138.47.0)
/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
/System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 153.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
Now type:
install_name_tool -change /usr/X11/lib/libfreetype.6.dylib @executable_path/../Frameworks/libfreetype.dylib sfml-graphics
and
otool -L sfml-graphics
should now give
sfml-graphics:
@executable_path/../Frameworks/sfml-graphics.framework/Versions/2.0.0/sfml-graphics (compatibility version 2.0.0, current version 2.0.0)
@executable_path/../Frameworks/sfml-window.framework/Versions/2.0.0/sfml-window (compatibility version 2.0.0, current version 2.0.0)
@executable_path/../Frameworks/sfml-system.framework/Versions/2.0.0/sfml-system (compatibility version 2.0.0, current version 2.0.0)
@executable_path/../Frameworks/libfreetype.dylib (compatibility version 14.0.0, current version 14.2.0)
/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 833.25.0)
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1138.47.0)
/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
/System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 153.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
Now your sfml-graphics framework does not depend on any library from the X11 directory. However, I noticed you had manually linked your application against freetype when adding the library to your Xcode project, which implies that your app depends on freetype from the X11 directory. You should not link your app against freetype unless it directly depends on it.
Thus:
- remove any reference to freetype in your Xcode project
- relink your app
- replace sfml-graphics.framework that is inside your app with the modified version
- copy libfreetype.dylib in your app next to sfml-graphics.framework