Vasantha Ganesh
Vasantha Ganesh

Reputation: 5090

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.

Upvotes: 0

Views: 666

Answers (1)

Vasantha Ganesh
Vasantha Ganesh

Reputation: 5090

  • You need to install objective-web's asm.jar
  • and jjfi.jar
  • add those to your classpath and voila!

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

Upvotes: 0

Related Questions