0

Is it possible to load the Teamspeak.so library by System.loadLibrary in java and access the methods declared in the .h files? (sources are the files from the ts3_sdk_3.0.3.2 - .h files from /include/teamspeak/serverlib.h; .so files from /bin/libts3server_linux_amd64.so)

Im able to load the library:

System.loadLibrary("ts3server_linux_amd64"); - works without error.

When i try to use a method i get a

java.lang.UnsatisfiedLinkError

Testcode:

public class main {

    static {
        System.loadLibrary("ts3server_linux_amd64");

    }

    public static void main(String[] args) {

        new main().onClientStartTalkingEvent();

    }

    private native void onClientStartTalkingEvent();
}

(.so file is stored in a lib folder and added to the classpath. OS is ubuntu).

Thanks and best regards

Thorsten S.
  • 4,144
  • 27
  • 41
BenniR6
  • 3
  • 1
  • What's your implementation of onClientStartTalkingEvent? – Philippe Marschall Aug 18 '15 at 12:00
  • The implementation looks like this: #ifndef SERVERLIB_H #define SERVERLIB_H #include #include #ifdef __cplusplus extern "C" { #endif struct ServerLibFunctions { void (*onClientStartTalkingEvent) (uint64 serverID, anyID clientID); void (*onClientStopTalkingEvent) (uint64 serverID, anyID clientID); (start of the serverlib.h file. I exspect it is stored in the .so library) – BenniR6 Aug 18 '15 at 13:11
  • do i need to use something like a pointer to the methods in de .h file of the .so library? i thought the "native void" implementation is the pointer? – BenniR6 Aug 18 '15 at 13:14

1 Answers1

1

Instead of loading the teamspeak .so you need to load the .so of your JNI code (which links against the teamspeak .so).

Edit

To call a native library from Java you need to write a JNI wrapper. This is a native library itself which you have to load from Java and can be called through native functions. If the native library you want to call is C (and not C++) you can have a look at projects like jnr-ffi or jna. These allow you to call C libraries without having to write a JNI wrapper.

Philippe Marschall
  • 4,452
  • 1
  • 34
  • 52