Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Debuggin JNI UnsatisfiedLinkError



Hi Kusti,

Here's a checklist for you.  JNI libraries must be:

-Built as Dynamic Libraries in Xcode (MACH_O_TYPE mh_dylib). Libraries of any other type (e.g. Static) do not load.
-Built as universal binaries. PowerPC libraries do not load on Intel-based Macs, nor vice-versa. See Technical Q&A QA1295, 'Java on Intel-based Macs'.
-Named libFoo.jnilib, where Foo is the name passed to System.loadLibrary
-Placed in a loadable library path. Possible paths include:
   - The Java Resources subdirectory of your application bundle (e.g. YourApp.app/Contents/Resources/Java)
   - The working directory at launch time (i.e. user.dir)
   - A Java extension directory listed in Technical Q&A QA1170, 'Important Java Directories on Mac OS X'
   - The Mac OS X dynamic library search path explained at http://developer.apple.com/documentation/DeveloperTools/Conceptual/DynamicLibraries/Articles/DynamicLibraryUsageGuidelines.html

You can also set the java.library.path system property at application launch time to specify an alternate installation path.  If your library fits all of these criteria it should be loading.  Feel free to send it along if it still does not after reviewing this list.


/*
  Matt Drance | Sharing Technologies Evangelist
  Worldwide Developer Relations
  
  Turn the next big thing from Apple into the next big thing from you
  WWDC 2007 | June 11-15, San Francisco
*/


On Apr 2, 2007, at 11:21 AM, Kustaa Nyholm wrote:

Hi,

I'm looking for ideas / techniques to debug JNI UnsatisfiedLinkError on Mac OS X

I'm trying to use a huge package, OpenCASCADE, which is an Open Source Solid Modeling Package written in C++. It's pretty mature and has been compiled succesfully on various Linuxes ans Windows. The build process is pretty much standard GNU make. Can't say it has been easy, but with I have been able to compile it on Mac OS with minimal changes. When I say huge, I mean it has some +5000 source modules taking up 170 MB on my disk, it takes almost five hours to compile on my 2 GHz Dual Core, when compiled it produces about 130 dynamic libraries in my /usr/local/lib. So it is a major piece of software and thus trying to track a problem, any problem, is, well, problematic.

A Java port is, sort of, available. The make system for the Java bindings is not as mature as the rest of the package but I've managed to compile it.

But when I try to use the library I get UnsatisfiedLinkError.

My test program is simply:

public class Main {
public static void main(String[] args) {
System.loadLibrary("jcas");
}
}

I'm pretty confident that the loadLibrary() actually finds the file (named 'libjcas.jnilib') as if I change the name I get a different variant of the same exception.

I've set my DYLD_LIBRARY_PATH

/Users/nyholku/occ-java/Jni/Darwin,/usr/local/lib,/usr/lib

I've used otool -L on the 'libjcas.jnilib' to find out the dependencies and that file seems to refer almost all of the OpenCASCADE libries in the /usr/local/lib, but hey, no problem, they are there and they are on the library path.

I've set the following variables to see what happens:

DYLD_PRINT_BINDINGS,DYLD_PRINT_LIBRARIES,DYLD_PRINT_LIBRARIES_POST_LAUNCH

and a huge listing is produced indicating that most of the libries are loaded and a lot of binding does happen. But the final climax is missing, I still get the UnsatisfiedLinkError.

So now I'm a little at loss on how to dig deeper. Obviously the project is too large for trial and error unless I can prune to problem down somehow.

But how, that is the question?

How can I found out what is missing or if something else is the problem?

I may add that I've tried a simple hello/jni in an attempt to verify that my link compile process is ok. I've also tried to 'empty' the jcas library so that it does not refer to anything and in this case the library compiles and links, runs and loads ok. So I think my compile/link process is ok. The only suspect is  that I need to use -ObjCpp flag to compile as the one of the awt files is by necessity Objective C. But I trust this is not the problem? Or could it be?

br Kusti




_______________________________________________
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:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden

References: 
 >Debuggin JNI UnsatisfiedLinkError (From: Kustaa Nyholm <email@hidden>)



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

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.