OpenJDK 9 & macOS: java.lang.UnsatisfiedLinkError: Library not loaded: @rpath/libfreetype.6.dylib
Some time ago I wrote a post on how to brew and manage multiple (Adopt)OpenJDK versions on your mac - which is my current java setup. Premised so, lately I wanted to install STM32CubeMX on my (freshly formatted) laptop and I incurred in this friendly error:
Andreas-MacBook-Pro:~ a.leofreddi$ ~/Downloads/en.STM32CubeMX_v5-0-1/SetupSTM32CubeMX-5.0.1.app/Contents/MacOs/SetupSTM32CubeMX-5_0_1_macos
chdir /Users/a.leofreddi/Downloads/en.STM32CubeMX_v5-0-1/SetupSTM32CubeMX-5.0.1.app/Contents/MacOs
current dir /Users/a.leofreddi/Downloads/en.STM32CubeMX_v5-0-1/SetupSTM32CubeMX-5.0.1.app/Contents/MacOs
Jul 11, 2019 11:21:46 AM INFO: Logging initialized at level 'INFO'
Jul 11, 2019 11:21:46 AM INFO: Commandline arguments:
Jul 11, 2019 11:21:47 AM INFO: Detected platform: mac_osx,version=10.14.5,arch=x86,symbolicName=null,javaVersion=9
Exception in thread "main" java.lang.UnsatisfiedLinkError: /Library/Java/JavaVirtualMachines/adoptopenjdk-9.jdk/Contents/Home/lib/libfontmanager.dylib: dlopen(/Library/Java/JavaVirtualMachines/adoptopenjdk-9.jdk/Contents/Home/lib/libfontmanager.dylib, 1): Library not loaded: @rpath/libfreetype.6.dylib
Referenced from: /Library/Java/JavaVirtualMachines/adoptopenjdk-9.jdk/Contents/Home/lib/libfontmanager.dylib
Reason: image not found
at java.base/java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2614)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2520)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:873)
at java.base/java.lang.System.loadLibrary(System.java:1857)
at java.desktop/sun.lwawt.macosx.LWCToolkit$1.run(LWCToolkit.java:94)
at java.desktop/sun.lwawt.macosx.LWCToolkit$1.run(LWCToolkit.java:83)
at java.base/java.security.AccessController.doPrivileged(Native Method)
Beautiful, isn't it? At first I've tried to switch to Java 8, and everything went fine. But I was really curious about why it fails with Java 9, so I digged a bit. From the error, it clearly looks like @rpath/libfreetype.6.dylib
is not found. So I went to give a look in /Library/Java/JavaVirtualMachines/adoptopenjdk-9.jdk/Contents/Home/lib
and... what?? libfreetype.dylib.6
is there, but not libfreetype.6.dylib
! Symlinking libfreetype.dylib.6
to libfreetype.6.dylib
did the trick :)