For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > March 2008 > wrong ELF class: ELFCLASS64 when trying to link dynamic .so library









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author wrong ELF class: ELFCLASS64 when trying to link dynamic .so library
lennart.rudeback@yahoo.com

2008-03-18, 8:13 am

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 <iostream>
#include <string.h>

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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com