wrong ELF class: ELFCLASS64 when trying to link dynamic .so libraryfrom Java/JNA - Unix

This is a discussion on wrong ELF class: ELFCLASS64 when trying to link dynamic .so libraryfrom Java/JNA - Unix ; Hello, I am having some trouble. I have spent a day or so browsing and experimenting, but I have not found any way around this problem. So I hope this is the correct forum to post my question: I am ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: wrong ELF class: ELFCLASS64 when trying to link dynamic .so libraryfrom Java/JNA

  1. wrong ELF class: ELFCLASS64 when trying to link dynamic .so libraryfrom Java/JNA

    Hello, I am having some trouble. I have spent a day or so browsing and
    experimenting, but I have not found any way around this problem. So I
    hope this is the correct forum to post my question:

    I am running The NetBeans 6.0 IDE, on Suse Linux 10.3, on an AMD64
    platform.
    I have included the C/C++ package to the IDE.

    I have "installed" JNA in order to be able to access native calls from
    Java. (I have a lot of C++ code I need to access in a web-service
    context, thus I would like a Java interface). As far as I have
    understood, the installation of JNA basically consists of linking to
    the jna.jar file and setting one system variable, "jna.library.path",
    to the dynamic .so library one wants to access.

    I have tried running the standard example, given at https://jna.dev.java.net/,
    where one prints "Hello World" from Java using the standard native C
    library, and that works fine for me:

    package com.sun.jna.examples;

    import com.sun.jna.Library;
    import com.sun.jna.Native;
    import com.sun.jna.Platform;

    /** Simple example of native library declaration and usage. */
    public class HelloWorld {

    public interface CLibrary extends Library {
    CLibrary INSTANCE = (CLibrary)
    Native.loadLibrary((Platform.isWindows() ? "msvcrt" :
    "c"),
    CLibrary.class);

    void printf(String format, Object... args);
    }

    public static void main(String[] args) {
    CLibrary.INSTANCE.printf("Hello, World");
    for (int i=0;i < args.length;i++) {
    CLibrary.INSTANCE.printf("Argument %d: %s\n", i, args[i]);
    }
    }
    }

    Nowas the next step, I am trying to start to build my own dynamic .so
    library from C/C++, to be able to access it from a Java context.
    Currently I keep the library extremely simple:

    #include
    #include

    using namespace std;

    int main(int argc, char** argv) {
    return (EXIT_SUCCESS);
    }

    void call_DLL_void()
    {
    /* Do nothing. */
    }

    Then I try to access the call_DLL_void() method from Java/JNA using:


    import com.sun.jna.Library;
    import com.sun.jna.Native;
    import com.sun.jna.Platform;

    public class Main {

    public interface CLibrary extends Library {
    CLibrary INSTANCE = (CLibrary) Native.loadLibrary("CPP_Test",
    CLibrary.class);

    void call_DLL_void();
    }

    public static void main(String[] args) {
    System.setProperty( "jna.library.path", "/root/Desktop" );
    CLibrary.INSTANCE.call_DLL_void(); /* Does nothing,
    excepting forcing access to the library. */
    }

    }


    Here I keep getting the runtime error " Unable to load library
    'CPP_Test': /root/Desktop/libCPP_Test.so: wrong ELF class: ELFCLASS64"
    when running from within the IDE.

    I realise that the conflict stems from the fact that the dynamic
    library has been built on an amd-64 platform. However JNA I supposed
    to support that, so somewhere I need to tell JNA that the platfrom is
    indeed amd-64.
    How do I do that?

    I have browsed through the sparse JNA documentation and examples, but
    have not managed to progress.

    I would be very thankful for advise.

    Best Regards,
    Lennie

  2. Re: wrong ELF class: ELFCLASS64 when trying to link dynamic .solibrary from Java/JNA

    lennart.rudeback@yahoo.com writes:

    > Here I keep getting the runtime error " Unable to load library
    > 'CPP_Test': /root/Desktop/libCPP_Test.so: wrong ELF class: ELFCLASS64"
    > when running from within the IDE.


    This means that a 32-bit executable attempted to dlopen() a 64-bit
    shared library. Such attempt fails with the error above.

    > I realise that the conflict stems from the fact that the dynamic
    > library has been built on an amd-64 platform. However JNA I supposed
    > to support that,


    It can't, unless the java program itself has been built as a
    64-bit binary.

    > so somewhere I need to tell JNA that the platfrom is
    > indeed amd-64.


    You can't tell it. You must use 64-bit version.

    According to this Sun page, such version is available:
    http://java.sun.com/j2se/1.5.0/jre/i...-linux-64.html

    Alternatively, you can build libCPP_Test.so in 32-bit mode (with
    '-m32' switch).

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

+ Reply to Thread