Adding the additional framework to the cc -dynamiclib command fixes it.
As in:
cc -dynamiclib -o libHiResTimer.jnilib com_cogstate_utils_HiResTimer.o
-framework JavaVM -framework CoreServices
A/Prof David Darby
Chief Medical Officer
CogState Ltd
Level 7, 21 Victoria St
Melbourne VIC 3000
Australia
Ph 613-9664-1300
Fx 613-9664-1301
M 0419-136-847
Em email@hidden
Begin forwarded message:
From: email@hidden
Date: 29 September 2004 1:29:40 AM
To: email@hidden
Subject: Re: Problem with compiling Microseconds for JNI
David Darby wrote:
| My Windows programmer has provided me with jni compatible .c and .h
| files which compile just fine on his system. It creates a HiResTimer
| dll returning microsecond elapsed times. He wishes me to compile this
| into a shared library (called libHiResTimer.jnilib) to place into the
| same folder to allow the java byte code to work on both platforms.
| (I've used Microseconds() as a first attempt at this).
|
| I've followed the instructions in the XCode documentation on JNI
using
| gcc and the command line. The calls are:
|
| cc -c -I/System/Library/Frameworks/JavaVM.framework/Headers
| com_cogstate_utils_HiResTimer.c
|
| which successfully creates the object file:
| com_cogstate_utils_HiResTimer.o
|
| Then:
|
| cc -dynamiclib -o libHiResTimer.jnilib
com_cogstate_utils_HiResTimer.o
| -framework JavaVM
|
| This fails to link with the following error:
|
| internal link edit command failed
| ld: com_cogstate_utils_HiResTimer.o illegal reference to symbol:
| _Microseconds defined in indirectly referenced dynamic library
| /System/Library/Frameworks/CoreServices.framework/Versions/A/
| Frameworks/CarbonCore.framework/Versions/A/CarbonCore
This says that Microseconds is defined in CoreServices.framework, not
JavaVM.framework, but you haven't sais that your code requires the
CoreServices framework to run. (In other words, the linker knows where
to find "Microseconds" only because Java uses
it. Your code won't have that advantage.)
| So, how do I include the correct extra shared library that contains
the
| Microseconds()?
Since the missing library is a framework (CoreServices.framework), the
same way you included the JavaVM.framework: "-framework CoreServices".
| (I apologize if it's trivially simple and I need to include a lib
from
| somewhere, but I tried without success to find and include all sorts
| of libs.)
The missing item isn't a library; it's a framework. Frameworks have
libraries at their core, but include a bunch of other stuff, too. I
suggest that you read the OS X overviews and learn how OS X handles
object code. JNI is tricky enough without doing i
t blind.
Glen Fisher
_______________________________________________
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