title: Shared libraries - Java 32 bit on 64bit Ubuntu
body: <p>I am trying to run a Bioinformatics program for MRS spectrosopy analysis called "jMRUI". The executable for this program is a .sh with the following code:</p>
  
  <pre><code>    java -Xss2m -mx1200m -Djava.library.path=lib -jar lib/mrui.jar
  </code></pre>
  
  <p>I have both the <a href="http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html" rel="nofollow noreferrer">64bit and 32bit</a> JDK 1.8 installed on my PC at the directory /usr/lib/jvm/.</p>
  
  <pre><code>    64bit found at: /usr/lib/jvm/jdk1.8.0_x64/bin/java
      32bit found at: /usr/lib/jvm/jdk1.8.0_x86/bin/java
  </code></pre>
  
  <p>The <em>pointer</em> symbolic link at /usr/bin/java points to /etc/alternatives/java which points to /usr/lib/jvm/jdk1.8.0_x64/bin/java if the 64bit version is currently selected or /usr/lib/jvm/jdk1.8.0_x86/bin/java if 32bit is currently selected. Permissions of all three are below.</p>
  
  <pre><code>    lrwxrwxrwx 1 root root 22 Jul  2 17:34 /usr/bin/java -&gt; /etc/alternatives/java
      lrwxrwxrwx 1 root root 34 Jul  2 18:29 /etc/alternatives/java -&gt; /usr/lib/jvm/jdk1.8.0_x(VER#)/bin/java
      -rwxr-xr-x 1 lillian lillian 5730 Mar 18 02:58 /usr/lib/jvm/jdk1.8.0_x64/bin/java
      -rwxr-xr-x 1 lillian lillian 5730 Mar 18 02:58 /usr/lib/jvm/jdk1.8.0_x86/bin/java
  </code></pre>
  
  <p>I can switch between java versions simply with a bash script that runs the following code:
  From 32bit java back to 64bit java:</p>
  
  <pre><code>    #!/bin/sh
      #the next 3 commands are only run initially to install the link alternative 
      #associations. I give everything the same priority of 1.
      sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_x64/bin/java" 1
      sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_x64/bin/javac" 1
      sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.8.0_x64/bin/javaws" 1
  
      echo 1 | sudo update-alternatives --config java
      echo 1 | sudo update-alternatives --config javac
      echo 1 | sudo update-alternatives --config javaws
  </code></pre>
  
  <p>From 64bit to 32bit:</p>
  
  <pre><code>    #!/bin/sh
      #the next 3 commands are only run initially to install the link alternative 
      #associations. I give everything the same priority of 1.
      sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_x86/bin/java" 1
      sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_x86/bin/javac" 1
      sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.8.0_x86/bin/javaws" 1
  
      echo 1 | sudo update-alternatives --config java
      echo 1 | sudo update-alternatives --config javac
      echo 1 | sudo update-alternatives --config javaws
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/9081962/java-is-installed-in-listing-but-execution-produces-java-no-such-file-or-d/9082947#9082947">This post</a> told me to also install the following packages for 32bit java. Here is output from all of the suggested test commands.</p>
  
  <ol>
  <li><p>readelf -l /usr/bin/java</p>
  
  <pre><code>Elf file type is EXEC (Executable file)
  Entry point 0x8048420
  There are 8 program headers, starting at offset 52
  Program Headers:
      Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
      PHDR           0x000034 0x08048034 0x08048034 0x00100 0x00100 R E 0x4
      INTERP         0x000134 0x08048134 0x08048134 0x00013 0x00013 R   0x1
         [Requesting program interpreter: /lib/ld-linux.so.2]
      LOAD           0x000000 0x08048000 0x08048000 0x00710 0x00710 R E 0x1000
      LOAD           0x000710 0x08049710 0x08049710 0x00144 0x0014c RW  0x1000
      DYNAMIC        0x00072c 0x0804972c 0x0804972c 0x00108 0x00108 RW  0x4
      NOTE           0x000148 0x08048148 0x08048148 0x00044 0x00044 R   0x4
      GNU_EH_FRAME   0x00069c 0x0804869c 0x0804869c 0x0001c 0x0001c R   0x4
      GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x4
  
  Section to Segment mapping:
  Segment Sections...
      00     
      01     .interp 
      02     .interp .note.ABI-tag .note.gnu.build-id .hash .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_d .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame 
      03     .ctors .dtors .jcr .data.rel.ro .dynamic .got .got.plt .data .bss 
      04     .dynamic 
      05     .note.ABI-tag .note.gnu.build-id 
      06     .eh_frame_hdr 
      07     
  </code></pre></li>
  <li><p>ls -l /lib/ld-linux.so.2</p>
  
  <pre><code>lrwxrwxrwx 1 root root 25 Apr 12 05:44 /lib/ld-linux.so.2 -&gt; i386-linux-gnu/ld-2.19.so
  </code></pre></li>
  <li><p>ldd java</p>
  
  <pre><code>linux-gate.so.1 =&gt;  (0xf775c000)
  libpthread.so.0 =&gt; /lib/i386-linux-gnu/libpthread.so.0 (0xf7728000)
  libjli.so =&gt; not found
  libdl.so.2 =&gt; /lib/i386-linux-gnu/libdl.so.2 (0xf7722000)
  libc.so.6 =&gt; /lib/i386-linux-gnu/libc.so.6 (0xf7573000)
  /lib/ld-linux.so.2 (0xf775d000) 
  </code></pre></li>
  <li><p>Since libjli.so was not found, I have tried to apt-get at pretty much any recommended package involved with i386. None have changed the "not found" status of libjli.so to found.</p></li>
  </ol>
  
  <p>When /usr/bin/java points to the 64bit java, jMRUI launches, but crashes when I try to upload an .SDAT file (basically when I open any file). When I try to open a file, I get this error message and then it hangs until you kill the process:</p>
  
  <pre><code>    Java HotSpot(TM) 64-Bit Server VM warning: You have loaded library 
      /home/lillian/Downloads/jMRUI-4.0/lib/libfftw.so which might have disabled stack 
      guard. The VM will try to fix the stack guard now.
      It's highly recommended that you fix the library with 'execstack -c &lt;libfile&gt;', 
      or link it with '-z noexecstack'.
      Exception in thread "Thread-1" java.lang.UnsatisfiedLinkError: 
      /home/lillian/Downloads/jMRUI-4.0/lib/libfftw.so: /home/lillian/Downloads/jMRUI-
      4.0/lib/libfftw.so: 
      wrong ELF class: ELFCLASS32 (Possible cause: architecture word width mismatch)
          at java.lang.ClassLoader$NativeLibrary.load(Native Method)
          at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1929)
          at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1847)
          at java.lang.Runtime.loadLibrary0(Runtime.java:870)
          at java.lang.System.loadLibrary(System.java:1119)
          at fft.Fft.&lt;clinit&gt;(Unknown Source)
          at mrui.data.FID.constructSpectrum(Unknown Source)
          at mrui.data.Data.constructSpectrum(Unknown Source)
          at mrui.data.Data.constructSpectrum(Unknown Source)
          at mrui.data.Data.addSignal(Unknown Source)
          at mrui.conversion.philips.FilePhil.loadData(Unknown Source)
          at mrui.plugin.conversion.ConversionManager.loadFile(Unknown Source)
          at mrui.plugin.conversion.FileManagementRead.loadInBackground(Unknown Source)
          at mrui.plugin.conversion.FileManagementRead.run(Unknown Source)
          at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>When /usr/bin/java points to the 32bit java, jMRUI does not launch at all, and I get this error message:</p>
  
  <pre><code>    ./jmrui.sh
      Jul 02, 2014 6:56:04 PM mrui.Launcher main
      INFO: Log properties loaded
      Exception in thread "main" java.lang.UnsatisfiedLinkError: 
      /usr/lib/jvm/jdk1.8.0_x86/jre/lib/i386/libawt_xawt.so: libXrender.so.1: 
      cannot open shared object file: No such file or directory
      at java.lang.ClassLoader$NativeLibrary.load(Native Method)
      at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1929)
      at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1814)
      at java.lang.Runtime.load0(Runtime.java:809)
      at java.lang.System.load(System.java:1083)
      at java.lang.ClassLoader$NativeLibrary.load(Native Method)
      at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1929)
      at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1835)
      at java.lang.Runtime.loadLibrary0(Runtime.java:870)
      at java.lang.System.loadLibrary(System.java:1119)
      at java.awt.Toolkit$3.run(Toolkit.java:1651)
      at java.awt.Toolkit$3.run(Toolkit.java:1649)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.awt.Toolkit.loadLibraries(Toolkit.java:1648)
      at java.awt.Toolkit.&lt;clinit&gt;(Toolkit.java:1683)
      at sun.awt.AppContext$2.run(AppContext.java:275)
      at sun.awt.AppContext$2.run(AppContext.java:264)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.awt.AppContext.initMainAppContext(AppContext.java:264)
      at sun.awt.AppContext.access$400(AppContext.java:133)
      at sun.awt.AppContext$3.run(AppContext.java:319)
      at sun.awt.AppContext$3.run(AppContext.java:302)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.awt.AppContext.getAppContext(AppContext.java:301)
      at javax.swing.SwingUtilities.appContextGet(SwingUtilities.java:1860)
      at javax.swing.UIManager.getLAFState(UIManager.java:243)
      at javax.swing.UIManager.setLookAndFeel(UIManager.java:529)
      at javax.swing.UIManager.setLookAndFeel(UIManager.java:579)
      at mrui.Launcher.main(Unknown Source)
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/16188672/wrong-elf-class-elfclass32-possible-cause-architecture-word-width-mismatch">This site</a> told me the 64bit error message is because jMRUI requires 32bit java, so that's why I have both.</p>
  
  <p>Again, <a href="https://stackoverflow.com/questions/9081962/java-is-installed-in-listing-but-execution-produces-java-no-such-file-or-d/9082947#9082947">this site</a> tells me 32bit java isn't working because I am "trying to run a 64bit system without a 32bit runtime environment".</p>
  
  <p>Lastly, <a href="https://stackoverflow.com/questions/7284129/jni-issue-on-linux-cannot-open-shared-object-file">this site</a> told me to add the -d32 option in my jMRUI.sh bash script. It did not change the shared library error message outcome.</p>
  
  <p>What oh what am I missing? I can't imagine I haven't given enough information, but if you need anything else to help debug this, let me know and I'll send the output your way. Thanks a million in advance!</p>