I am attempting to bundle FreeType with my Mac build of OpenJDK9, but am having trouble with references to libfreetype after building is completed. I am packaging the JDK with my application, and do not want the end user to have to install FreeType in order to get the application to work (the JDK7 version we use does what I want, but I wasn't the one to build that so don't know what they did to get this to work).
After downloading FreeType 2.5.3 (I've also used 2.8.1 but I don't think it matters which version is used as OpenJDK says anything over 2.3 should work for Java 9), I am running (just filling in paths with variables since they don't really matter)
./configure prefix=$DOWNLOAD_PATH/freetype-2.5.3
make
make install
Then to build my JDK, I'm running
bash ./configure --with-freetype=$DOWNLOAD_PATH/freetype-2.5.3 --with-boot-jdk=$PATH_TO_JDK1.8/Contents/Home --disable-warnings-as-errors
make images
This builds the JDK just fine and bundles libfreetype.dylib.6 into the jdk/lib directory, but when I open up libfontmanager.dylib, I can see that it is pointing to $DOWNLOAD_PATH/freetype-2.5.3/lib/libfreetype.6.dylib
instead of @rpath/libfreetype.6.dylib
Because it is not using the relative path (even though it successfully bundled the file), when I run the application it is looking for that $DOWNLOAD_PATH to exist to find the dylib file (which it doesn't because that location was only on the Mac I used to build the JDK), so I get an error that looks like this:
Exception in thread "main" java.lang.UnsatisfiedLinkError: /Applications/Launcher.app/Contents/PlugIns/jdk-9.jdk/Contents/Home/jre/lib/libfontmanager.dylib:
dlopen(/Applications/Launcher.app/Contents/PlugIns/jdk-9.jdk/Contents/Home/jre/lib/libfontmanager.dylib,
1): Library not loaded: /$DOWNLOAD_PATH/freetype-2.5.3/lib/libfreetype.6.dylib
Referenced from: /Applications/Launcher.app/Contents/PlugIns/jdk-9.jdk/Contents/Home/jre/lib/libfontmanager.dylib
Reason: image not found
at java.base/java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.base/java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.base/java.lang.ClassLoader.loadLibrary(Unknown Source)
...
How do I get my build to use @rpath
here instead of the absolute path where FreeType was pulled in from? It is successfully bundling the file (libfreetype.6.dylib is in the jre/lib directory), just not pointing to it in libfontmanager.dylib.
For anyone concerned, there was a JDK bug for this issue that was closed back in December which acknowledges the bug and provides a workaround for it by using install_name_tool to manually modify the dylib file to use the @rpath after the jdk has been created.
Here's the link to the bug: https://bugs.openjdk.java.net/browse/JDK-8139653?jql=text%20~%20%22freetype%22