Is this error caused by a 64-bit library being accessed by a Java program running in a 32-bit JVM?

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-03-24T20:19:23Z Indexed on 2010/03/24 20:23 UTC
Read the original article Hit count: 558

Filed under:
|
|
|
|

I'm trying to create a simple Java app that uses JNI to call some native functions. I've followed the examples in the JNI Programming Guide and can't seem to get them to work. I have the following Hello World program, written in Java:

class HelloWorld {
    private native void print();

    public static void main(String [] args) {
        new HelloWorld().print();
    }

    static {
        System.load("/home/mike/Desktop/libHelloWorld.so");
    }
}

I compile it using javac HelloWorld.java, just like normal. Then I run javah -jni HelloWorld, and finally the following:

gcc34 -shared -fpic -o libHelloWorld.so -I/<path to JDK>/include -I/<path to JDK>/include/linux HelloWorld.c

gcc34 is the name of the GCC program on my machine here at work (I don't control that) and I obviously place the real path to the JDK in that command. When I run my program, using the standard java HelloWorld, I get an error saying the following:

Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/mike/Desktop/libHelloWorld.so: /home/mike/Desktop/libHelloWorld.so: wrong ELF class: ELFCLASS64 (Possible causes: architecture word width mismatch)
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1778)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1674)
    at java.lang.Runtime.load0(Runtime.java:770)
    at java.lang.System.load(System.java:1003)
    at HelloWorld.<clinit>(HelloWorld.java:8)
Could not find the main class: HelloWorld. Program will exit.

I know I'm running a 32-bit JVM (and unfortunately, as of right now, I'm not allowed to get a 64-bit JVM). I tried telling GCC to compile in 32-bit mode using the "-m32" option, but we don't have (and again, can't get) what we need for that.

Does this sound like a 32/64-bit conflict or something else?

© Stack Overflow or respective owner

Related posts about java

Related posts about c