Mailing Lists: Apple Mailing Lists

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

JNI without XCode?



Is anyone doing JNI without XCode?

I appreciate that it's convenient to let XCode drive, and Apple's sample works just fine, but I want to keep my build command-line driven so it'll work on Windows too.

I have a single class so far with one native method. I've javah'ed it to create the .h file, implemented with a .c file, and then I compile with:

cadamson% gcc -c -g -I/System/Library/Frameworks/JavaVM.framework/ Versions/1.4.2/Headers -dynamiclib -o libmateria.jnilib org_jvnet_materia_metadata_QTMetaData.c

There's a fair amount of guesswork in these args -- I've been in Java- land for 8 years and haven't done serious C since I was in college. I think I need the "-c" because I'm developing a library and not an executable (with a main method). The -g and -dynamiclib flags are things I found on the web... not sure I need them... it was a late night.

This creates my specified .o file, but I'm not sure if it's any good. When I try to run Java code to load the library, even with an explicit reference to the jnilib's path, the linking fails:

cadamson% java -classpath build -Djava.library.path=/Users/cadamson/ dev/materia/native org.jvnet.materia.metadata.TestQTMetaData
Exception in thread "main" java.lang.UnsatisfiedLinkError: /Users/ cadamson/dev/materia/native/libmateria.jnilib:
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1586)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1511)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:834)
at org.jvnet.materia.metadata.TestQTMetaData.<clinit> (Unknown Source)


So, is it obvious what I'm doing wrong, and if not, has anyone put up a page or other resource for working with JNI on OSX without using XCode?

Thanks much in advance.

And yes, when I have something useful working, I'll be sharing  :-)

--Chris

_______________________________________________
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


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.