Shared libraries - Java 32 bit on 64bit Ubuntu

18,089

Having a look at the error messages, I have some conclusions:

  • you definitely need to run the 32 bit version, the native library in jMRUI-4.0/lib/libfftw.so is ELF32

  • when you run the 32 bit version, the system looks for a missing library: 'libXrender.so.1' (the 32bit version).

Install the package "libxrender1:i386" (libXrender 32bit) and try again with JDK 32 bit.

Share:
18,089
lrthistlethwaite
Author by

lrthistlethwaite

Degrees: PhD in Computational Biology BS in Computer Science BS in Behavioral Neuroscience. I'm currently a Senior Data Scientist at Parenthetic, where I specialize in building deep neural models specifically for natural language processing tasks.

Updated on June 04, 2022

Comments

  • lrthistlethwaite
    lrthistlethwaite almost 2 years

    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:

        java -Xss2m -mx1200m -Djava.library.path=lib -jar lib/mrui.jar
    

    I have both the 64bit and 32bit JDK 1.8 installed on my PC at the directory /usr/lib/jvm/.

        64bit found at: /usr/lib/jvm/jdk1.8.0_x64/bin/java
        32bit found at: /usr/lib/jvm/jdk1.8.0_x86/bin/java
    

    The pointer 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.

        lrwxrwxrwx 1 root root 22 Jul  2 17:34 /usr/bin/java -> /etc/alternatives/java
        lrwxrwxrwx 1 root root 34 Jul  2 18:29 /etc/alternatives/java -> /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
    

    I can switch between java versions simply with a bash script that runs the following code: From 32bit java back to 64bit java:

        #!/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
    

    From 64bit to 32bit:

        #!/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
    

    This post told me to also install the following packages for 32bit java. Here is output from all of the suggested test commands.

    1. readelf -l /usr/bin/java

      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     
      
    2. ls -l /lib/ld-linux.so.2

      lrwxrwxrwx 1 root root 25 Apr 12 05:44 /lib/ld-linux.so.2 -> i386-linux-gnu/ld-2.19.so
      
    3. ldd java

      linux-gate.so.1 =>  (0xf775c000)
      libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xf7728000)
      libjli.so => not found
      libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xf7722000)
      libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xf7573000)
      /lib/ld-linux.so.2 (0xf775d000) 
      
    4. 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.

    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:

        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 <libfile>', 
        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.<clinit>(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)
    

    When /usr/bin/java points to the 32bit java, jMRUI does not launch at all, and I get this error message:

        ./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.<clinit>(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)
    

    This site told me the 64bit error message is because jMRUI requires 32bit java, so that's why I have both.

    Again, this site tells me 32bit java isn't working because I am "trying to run a 64bit system without a 32bit runtime environment".

    Lastly, this site told me to add the -d32 option in my jMRUI.sh bash script. It did not change the shared library error message outcome.

    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!

  • lrthistlethwaite
    lrthistlethwaite almost 10 years
    YES YES YES. Morgano you are fantastic! I was trying to install the package "libxrender", but that was "invalid" and now I know why! For future reference, how did you know what the package name was called and to put the colon i386, etc? I am still learning about how Ubuntu pulls packages and how one knows the names of the packages they need. You have no idea how grateful I am to have solved this!
  • morgano
    morgano almost 10 years
    I've also had problems with native libraries in the past... As your distro is 64 bit, the packages by default are 64 bit, so they put something to the name of the 32 bit package to diferenciate it from the main one (that's not a standard though), I just searched for the packages which names contained 'xrender' with aptitude search xrender ("aptitute" is a command-line front-end to the apt-get system, nicer to use than the later, you could also use synaptic) that brought me the names of the packages matching with 'xrender', and voila! rest is history
  • lrthistlethwaite
    lrthistlethwaite almost 10 years
    Aptitude is seriously amazing. Thanks for this tip, morgano!