Need help tring to run a java game: error init: Could not locate OpenAL library

The game seems to require java 7 so I used an old version. The game runs if I disable the sound. Otherwise I get an error about OpenAL.

The game ships its own “libopenal64.so” (in native/linux). I’m not sure if I should use it or use nixos.openal.

A “game key” is needed to reach the part where it crashes.

Any ideas?

Should java be able to find the so file with -Djava.library.path=$out/native/linux and --suffix LD_LIBRARY_PATH : $out/native/linux?

The game also ship its own jre. I thought maybe I could try to patchelf it but it was a pita and I’m not sure it would work.

let
  oldPkgs2 = builtins.fetchGit { url = https://github.com/NixOS/nixpkgs-channels.git; ref = "nixos-18.03"; };
  oldPkgs = import oldPkgs2 {};
  nixpkgs = import <nixpkgs> {};
  
  libPath = with nixpkgs; nixpkgs.stdenv.lib.makeLibraryPath [
    libGL
    xorg.libX11
    xorg.libXcursor
    xorg.libXext
    xorg.libXrandr
    xorg.libXxf86vm
  ];

in
with nixpkgs;
stdenv.mkDerivation {
  name = "starsector-0.9a-RC10";
  src = fetchurl {
    url = http://s3.amazonaws.com/fractalsoftworks/starsector/starsector_linux-0.9a-RC10.zip;
    sha256 = "14mlc1xxj3dym0zywgq4qhh6ad9v9ax65rna21i8lymmwasdh8lb";
  };

  buildInputs = [
    pkgs.unzip
    makeWrapper
  ];

  installPhase = ''
    mkdir -p "$out/bin"

    cp -r {*.jar,data,graphics,native,sounds} $out/

    makeWrapper ${oldPkgs.openjdk7.jre}/bin/java $out/bin/starsector \
    --add-flags "-server -XX:CompilerThreadPriority=1 -XX:+CompilerThreadHintNoPreempt -Djava.library.path=$out/native/linux -Xms1536m -Xmx1536m -Xss1024k -classpath janino.jar:commons-compiler.jar:commons-compiler-jdk.jar:starfarer.api.jar:starfarer_obf.jar:jogg-0.0.7.jar:jorbis-0.0.15.jar:json.jar:lwjgl.jar:jinput.jar:log4j-1.2.9.jar:lwjgl_util.jar:fs.sound_obf.jar:fs.common_obf.jar:xstream-1.4.10.jar -Dcom.fs.starfarer.settings.paths.saves=/tmp/start/saves -Dcom.fs.starfarer.settings.paths.screenshots=/tmp/start/screenshots -Dcom.fs.starfarer.settings.paths.mods=/tmp/start/mods -Dcom.fs.starfarer.settings.paths.logs=/tmp/starsector.log com.fs.starfarer.StarfarerLauncher" \
    --suffix LD_LIBRARY_PATH : $out/native/linux \
    --suffix LD_LIBRARY_PATH : ${libPath}
  '';
}

I also tried patching the so files with:

    for exe in $out/native/linux/*.so{,.*} ; do
      patchelf --set-rpath "$out/native/linux:${libPath}:${oldPkgs.openjdk7.jre}/lib/openjdk/jre/lib/amd64" "$exe"
    done
error init: Could not locate OpenAL library.
2302 [Thread-5] ERROR sound.new  - org.lwjgl.LWJGLException: Could not locate OpenAL library.
org.lwjgl.LWJGLException: Could not locate OpenAL library.
	at org.lwjgl.openal.AL.create(AL.java:156)
	at org.lwjgl.openal.AL.create(AL.java:102)
	at org.lwjgl.openal.AL.create(AL.java:206)
	at sound.new$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at sound.new.o00000(Unknown Source)
	at com.fs.starfarer.combat.CombatMain.main(Unknown Source)
	at com.fs.starfarer.StarfarerLauncher$1.run(Unknown Source)
	at java.lang.Thread.run(Thread.java:745)
2369 [Thread-5] ERROR com.fs.starfarer.combat.CombatMain  - java.lang.NullPointerException
java.lang.NullPointerException
	at sun.awt.X11FontManager.getDefaultPlatformFont(X11FontManager.java:779)
	at sun.font.SunFontManager$2.run(SunFontManager.java:433)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.font.SunFontManager.<init>(SunFontManager.java:376)
	at sun.awt.X11FontManager.<init>(X11FontManager.java:32)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at java.lang.Class.newInstance(Class.java:383)
	at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
	at sun.font.SunFontManager.getInstance(SunFontManager.java:250)
	at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:264)
	at sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1030)
	at javax.swing.JComponent.getFontMetrics(JComponent.java:1625)
	at javax.swing.plaf.basic.BasicGraphicsUtils.getPreferredButtonSize(BasicGraphicsUtils.java:276)
	at javax.swing.plaf.basic.BasicButtonUI.getPreferredSize(BasicButtonUI.java:376)
	at javax.swing.plaf.basic.BasicButtonUI.getMinimumSize(BasicButtonUI.java:366)
	at javax.swing.JComponent.getMinimumSize(JComponent.java:1743)
	at javax.swing.plaf.basic.BasicOptionPaneUI.addButtonComponents(BasicOptionPaneUI.java:692)
	at javax.swing.plaf.basic.BasicOptionPaneUI.createButtonArea(BasicOptionPaneUI.java:630)
	at javax.swing.plaf.basic.BasicOptionPaneUI.installComponents(BasicOptionPaneUI.java:178)
	at javax.swing.plaf.basic.BasicOptionPaneUI.installUI(BasicOptionPaneUI.java:141)
	at javax.swing.JComponent.setUI(JComponent.java:665)
	at javax.swing.JOptionPane.setUI(JOptionPane.java:1861)
	at javax.swing.JOptionPane.updateUI(JOptionPane.java:1883)
	at javax.swing.JOptionPane.<init>(JOptionPane.java:1846)
	at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:858)
	at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:667)
	at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:638)
	at org.lwjgl.J2SESysImplementation.alert(J2SESysImplementation.java:56)
	at org.lwjgl.Sys.alert(Sys.java:213)
	at com.fs.starfarer.combat.CombatMain.main(Unknown Source)
	at com.fs.starfarer.StarfarerLauncher$1.run(Unknown Source)
	at java.lang.Thread.run(Thread.java:745)
2377 [Thread-5] ERROR com.fs.starfarer.StarfarerLauncher  - java.lang.NullPointerException
java.lang.NullPointerException
	at sun.awt.X11FontManager.getDefaultPlatformFont(X11FontManager.java:779)
	at sun.font.SunFontManager$2.run(SunFontManager.java:433)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.font.SunFontManager.<init>(SunFontManager.java:376)
	at sun.awt.X11FontManager.<init>(X11FontManager.java:32)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at java.lang.Class.newInstance(Class.java:383)
	at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
	at sun.font.SunFontManager.getInstance(SunFontManager.java:250)
	at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:264)
	at sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1030)
	at javax.swing.JComponent.getFontMetrics(JComponent.java:1625)
	at javax.swing.plaf.basic.BasicGraphicsUtils.getPreferredButtonSize(BasicGraphicsUtils.java:276)
	at javax.swing.plaf.basic.BasicButtonUI.getPreferredSize(BasicButtonUI.java:376)
	at javax.swing.plaf.basic.BasicButtonUI.getMinimumSize(BasicButtonUI.java:366)
	at javax.swing.JComponent.getMinimumSize(JComponent.java:1743)
	at javax.swing.plaf.basic.BasicOptionPaneUI.addButtonComponents(BasicOptionPaneUI.java:692)
	at javax.swing.plaf.basic.BasicOptionPaneUI.createButtonArea(BasicOptionPaneUI.java:630)
	at javax.swing.plaf.basic.BasicOptionPaneUI.installComponents(BasicOptionPaneUI.java:178)
	at javax.swing.plaf.basic.BasicOptionPaneUI.installUI(BasicOptionPaneUI.java:141)
	at javax.swing.JComponent.setUI(JComponent.java:665)
	at javax.swing.JOptionPane.setUI(JOptionPane.java:1861)
	at javax.swing.JOptionPane.updateUI(JOptionPane.java:1883)
	at javax.swing.JOptionPane.<init>(JOptionPane.java:1846)
	at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:858)
	at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:667)
	at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:638)
	at org.lwjgl.J2SESysImplementation.alert(J2SESysImplementation.java:56)
	at org.lwjgl.Sys.alert(Sys.java:213)
	at com.fs.starfarer.combat.CombatMain.main(Unknown Source)
	at com.fs.starfarer.StarfarerLauncher$1.run(Unknown Source)
	at java.lang.Thread.run(Thread.java:745)
Exception in thread "Thread-5" java.lang.NullPointerException
	at sun.awt.X11FontManager.getDefaultPlatformFont(X11FontManager.java:779)
	at sun.font.SunFontManager$2.run(SunFontManager.java:433)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.font.SunFontManager.<init>(SunFontManager.java:376)
	at sun.awt.X11FontManager.<init>(X11FontManager.java:32)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at java.lang.Class.newInstance(Class.java:383)
	at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
	at sun.font.SunFontManager.getInstance(SunFontManager.java:250)
	at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:264)
	at sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1030)
	at javax.swing.JComponent.getFontMetrics(JComponent.java:1625)
	at javax.swing.plaf.basic.BasicGraphicsUtils.getPreferredButtonSize(BasicGraphicsUtils.java:276)
	at javax.swing.plaf.basic.BasicButtonUI.getPreferredSize(BasicButtonUI.java:376)
	at javax.swing.plaf.basic.BasicButtonUI.getMinimumSize(BasicButtonUI.java:366)
	at javax.swing.JComponent.getMinimumSize(JComponent.java:1743)
	at javax.swing.plaf.basic.BasicOptionPaneUI.addButtonComponents(BasicOptionPaneUI.java:692)
	at javax.swing.plaf.basic.BasicOptionPaneUI.createButtonArea(BasicOptionPaneUI.java:630)
	at javax.swing.plaf.basic.BasicOptionPaneUI.installComponents(BasicOptionPaneUI.java:178)
	at javax.swing.plaf.basic.BasicOptionPaneUI.installUI(BasicOptionPaneUI.java:141)
	at javax.swing.JComponent.setUI(JComponent.java:665)
	at javax.swing.JOptionPane.setUI(JOptionPane.java:1861)
	at javax.swing.JOptionPane.updateUI(JOptionPane.java:1883)
	at javax.swing.JOptionPane.<init>(JOptionPane.java:1846)
	at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:858)
	at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:667)
	at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:638)
	at org.lwjgl.J2SESysImplementation.alert(J2SESysImplementation.java:56)
	at org.lwjgl.Sys.alert(Sys.java:213)
	at com.fs.starfarer.StarfarerLauncher$1.run(Unknown Source)
	at java.lang.Thread.run(Thread.java:745)
1 Like

I hit this error as well the other day. Did you ever figure out a nice way of fixing this?

The difficulty is when jar files embed ELF executables, it becomes hard to patch them with the right .ld.so preloader. A solution is to put the .ld.so back into the same path as other linux distributions: Runtime alternative to `patchelf --set-interpreter` - #5 by volth

2 Likes