javaffiunsatisfiedlinkerrorjnr

JNR UnsatisfiedLinkError


This question might be related to this and a ton other UnsatisfiedLinkError questions.

I'm trying to run the following code.

import jnr.ffi.LibraryLoader;
import jnr.ffi.types.pid_t;

/**
 * Gets the process ID of the current process, and that of its parent.
*/
public class Getpid {
    public interface LibC  {
        public @pid_t long getpid();
        public @pid_t long getppid();
    }

    public static void main(String[] args) {
        LibC libc = (LibC) LibraryLoader.create(LibC.class).load("c");

        System.out.println("pid=" + libc.getpid() + " parent pid=" + libc.getppid());
    }
}

The code compiles correctly but refuses to run,

(compilation step)

javac -cp /usr/share/java/jnr-ffi.jar:. Getpid.java 

(running step)

java -cp /usr/share/java/jnr-ffi.jar:. Getpid

While running I get this error.


Solution

  • Compile with this:

    javac -cp /usr/share/java/jnr-ffi.jar:.:/usr/lib/java/jffi.jar:/usr/lib/java/jffi-native.jar:/usr/share/java/objectweb-asm/asm.jar Getpid.java
    

    and run with this:

    java -cp /usr/share/java/jnr-ffi.jar:.:/usr/lib/java/jffi.jar:/usr/lib/java/jffi-native.jar:/usr/share/java/objectweb-asm/asm.jar Getpid