Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: UnsatisfiedLinkError after building a JNI Library
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: UnsatisfiedLinkError after building a JNI Library



I forgot to mention in my last email that I'm building and running on a Quad-Core Intel Xeon processor, so I don't know why I would need a universal binary to run on my machine.

Also, when I run file and otool -L on the new library, I get this:

miguel-munozs-mac-pro:Piddy miguel$ file libPiddy.jnilib
libPiddy.jnilib: Mach-O universal binary with 3 architectures
libPiddy.jnilib (for architecture i386): Mach-O dynamically linked shared library i386
libPiddy.jnilib (for architecture ppc7400): Mach-O dynamically linked shared library ppc
libPiddy.jnilib (for architecture ppc64): Mach-O 64-bit dynamically linked shared library ppc64
miguel-munozs-mac-pro:Piddy miguel$ otool -L libPiddy.jnilib
libPiddy.jnilib:
libPiddy.jnilib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4)


-- Miguel Muñoz


On Jun 16, 2009, at 3:03 PM, Pratik Solanki wrote:

Could you try running with Update 4 that we just released yesterday? That should give you more descriptive UnsatisfiedLinkErrors (for the most part).

Pratik

On Jun 16, 2009, at 1:59 PM, Miguel Muñoz wrote:

Greg Guerin wrote

The following works perfectly for me.

I did exactly what you showed, but it didn't work for me. The output is below, along with answers to your later question, and Mike Hall's question.


First of all, since your java code called System.loadLibrary() in the static block before calling main, I moved the call to main so I could run some tests first. The tests verify that the library is on java.library.path. Here's my Piddy.java:


File Piddy.java: ----- import java.io.File; import java.io.IOException; import java.util.*;

public class Piddy
{
public static void main( String[] args )
{
final String libPath = System.getProperty("java.library.path");
System.out.println( "java.library.path = " + libPath );


final String baseLibName = "Piddy";
final String libname = "lib" + baseLibName + ".jnilib";
final StringTokenizer stk = new StringTokenizer(libPath, ":");
while (stk.hasMoreTokens()) {
final String path = stk.nextToken();
fileExists(path, libname);
}
System.out.println("Loading Library");
System.loadLibrary( "Piddy" );


  System.out.println( "pid = " + pid() );
  System.out.println( "ppid = " + ppid() );
}

private static void fileExists(String dir, String libname) {
File libfile = new File(dir, libname);
String libFileName = libfile.toString();
System.err.println(libFileName);
System.err.println("Library exists = " + libfile.exists());
if (libfile.exists()) {
try {
String absolutePath = libfile.getCanonicalPath();
if (! absolutePath.equals(libFileName)) {
System.err.println(absolutePath);
}
} catch (IOException e) {
e.printStackTrace(); // shouldn't happen
}
}
if (libfile.exists()) {
Calendar timeStamp = Calendar.getInstance();
timeStamp.setTimeInMillis(libfile.lastModified());
System.err.println(" Modified at " + timeStamp.getTime());
}
System.err.println("");
}


private static native int pid();


private static native int ppid(); }

End Piddy.java


My Piddy.c is exactly the same as yours. Here's my command-line output:


(Please note that lsf is aliased to ls -F. Also, I include the output of the file and otool commands at the end.)

Aside from my change to Piddy.java, everything follows your example exactly.

miguel-munozs-mac-pro:Piddy miguel$ rm Piddy.h
miguel-munozs-mac-pro:Piddy miguel$ lsf
Piddy.c Piddy.java
miguel-munozs-mac-pro:Piddy miguel$ javac Piddy.java
miguel-munozs-mac-pro:Piddy miguel$ javah -jni Piddy
miguel-munozs-mac-pro:Piddy miguel$ gcc -x c -I/System/Library/ Frameworks/JavaVM.framework/Headers -c Piddy.c -o Piddy.o
miguel-munozs-mac-pro:Piddy miguel$ gcc -dynamiclib -o libPiddy.jnilib Piddy.o
miguel-munozs-mac-pro:Piddy miguel$ java Piddy
java.library.path = .:/Library/Java/Extensions:/System/Library/Java/ Extensions:/usr/lib/java
./libPiddy.jnilib
Library exists = true
/Users/miguel/DevProjects/Piddy/libPiddy.jnilib
Modified at Tue Jun 16 13:22:29 PDT 2009


/Library/Java/Extensions/libPiddy.jnilib
Library exists = false

/System/Library/Java/Extensions/libPiddy.jnilib
Library exists = false

/usr/lib/java/libPiddy.jnilib
Library exists = false

Loading Library
Exception in thread "main" java.lang.UnsatisfiedLinkError: /Users/ miguel/DevProjects/Piddy/libPiddy.jnilib:
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1822)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1739)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1030)
at Piddy.main(Piddy.java:30)
miguel-munozs-mac-pro:Piddy miguel$ file libPiddy.jnilib
libPiddy.jnilib: Mach-O dynamically linked shared library i386
miguel-munozs-mac-pro:Piddy miguel$ otool -L libPiddy.jnilib
libPiddy.jnilib:
libPiddy.jnilib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4)
miguel-munozs-mac-pro:Piddy miguel$ lsf
Piddy.c Piddy.class Piddy.h Piddy.java Piddy.o libPiddy.jnilib*
miguel-munozs-mac-pro:Piddy miguel$


-- Miguel Muñoz _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Re: UnsatisfiedLinkError after building a JNI Library (From: Miguel Muñoz <email@hidden>)
 >Re: UnsatisfiedLinkError after building a JNI Library (From: Pratik Solanki <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.