I wanted to build JNA under MacOSX so that I could do some debugging
by modifying the JNA source code.
Since I'm using a devel version of the JDK, it is probably not worth
trying to change jna yet, but others might find these instructions of
interest.
Below is a dump of my notes at
http://chess.eecs.berkeley.edu/ptexternal/wiki/Main/JNA#BuildingJNAUnderMacOSXWithJava1.7
Sadly, Apple's Java story is rather lacking. I installed the Java 1.7
preview for Mac OS X and now I can't seem to compile code that uses
jni.h.
When compiling jna, I get:
[exec] dispatch.c:79:17: error: /System/Library/Frameworks/
JavaVM.framework/Headers/jni.h: Too many levels of symbolic links
This is because jni.h is a link back on to itself:
lrwxr-xr-x 1 root wheel 30 Jul 28 2011 /System/Library/Frameworks/
JavaVM.framework/Headers/jni.h -> ../../CurrentJDK/Headers/jni.h
I went to
https://developer.apple.com/downloads/index.action
downloaded "Java for Mac OS X 10.7 Developer Package" and installed
it, and the problem was not solved.
It appears that the issue here is that Apple's Java 1.6 used the Mac
OS X "Frameworks" directory layout and Java 1.7 from Oracle uses the
Java directory layout. Personally, I prefer the Java layout, since
Java is "write once, test everywhere". Having a different directory
layout under Mac OS X made things more difficult.
I'm not sure how my directory structure was broken, but the directory
Headers directory itself had mod times of February 16, 2012, which is
probably when I upgraded to Mac OS X 10.7.3.
Apple is no longer supporting Java and it is really starting to show.
So, I decided to move forward with the Java 1.7 preview. I needed to
remove the broken jni.h links, so I did:
sudo -i
cd /System/Library/Frameworks/JavaVM.framework
mv Headers Headers.1.6
ln -s /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/
include Headers
Download the jna sources using git:
git clone
https://github.com/twall/jna.git
Run
ant
Problem: ant fails with "checking whether the C compiler works... no"
native:
[exec] configure: WARNING: if you wanted to set the --build type,
don't use --host.
[exec] If a cross compiler is detected then cross compConfiguring
libffi (amd64)
[exec] ile mode will be used
[exec] checking build system type... x86_64-apple-darwin11.3.0
[exec] checking host system type... x86_64-apple-darwin
[exec] checking target system type... x86_64-apple-darwin
[exec] checking for gsed... sed
[exec] checking for a BSD-compatible install... /usr/bin/install -c
[exec] checking whether build environment is sane... yes
[exec] configure: error: in `/Users/cxh/src/jna/build-d64/native/
libffi':
[exec] configure: error: C compiler cannot create executables
[exec] See `cchecking for amd64-apple-darwin-strip... no
[exec] checking for strip... strip
[exec] checking for a thread-safe mkdir -p... /Users/cxh/src/
jnonfig.log' for more details
[exec] a/native/libffi/install-sh -c -d
[exec] checking for gawk... no
[exec] checking for mawk... no
[exec] checking for nawk... no
[exec] checking for awk... awk
[exec] checking whether make sets $(MAKE)... yes
[exec] checking for amd64-apple-darwin-gcc... gcc -m64
[exec] checking whether the C compiler works... no
[exec] make: *** [/Users/cxh/src/jna/build-d64/native/libffi/.libs/
libffi.a] Error 77
What is happening here is that the Mac OS X Java 1.7.0_04-ea returns
amd64 for various properties.
The solution is to do
ant clean
ant -DARCH=x86_64
Problem: "jni_md.h: No such file or directory"
ant -DARCH=x86_64 fails with:
[exec] /System/Library/Frameworks/JavaVM.framework/Headers/jni.h:
45:20: error: jni_md.h: No such file or directory
My solution was to edit jna/native/Makefile.
Change:
ifeq ($(OS),darwin)
JAVA_INCLUDES=-I/System/Library/Frameworks/JavaVM.framework/Headers
to
ifeq ($(OS),darwin)
JAVA_INCLUDES=-I/System/Library/Frameworks/JavaVM.framework/Headers -I/
System/Library/Frameworks/JavaVM.framework/Headers/darwin
Rerun:
ant clean
ant -DARCH=x86_64
]
Problem: "‘JAWT_MacOSXDrawingSurfaceInfo’ undeclared"
[exec] dispatch.c:2865: error: ‘JAWT_MacOSXDrawingSurfaceInfo’
undeclared (first use in this function)
See
http://www.mail-archive.com/bsd-po...@openjdk.java.net/msg01291.html
Workaround: Edit jna/native/dispatch.c and search for
JAWT_MacOSXDrawingSurfaceInfo. Change
#elif __APPLE__
// WARNING: the view ref is not guaranteed to be stable except
during
// component paint (see
jni_md.h)
JAWT_MacOSXDrawingSurfaceInfo* mdsi =
(JAWT_MacOSXDrawingSurfaceInfo*)dsi->platformInfo;
[$[Get Code]]
to
#elif __APPLEXXX__
// WARNING: the view ref is not guaranteed to be stable except
during
// component paint (see
jni_md.h)
JAWT_MacOSXDrawingSurfaceInfo* mdsi =
(JAWT_MacOSXDrawingSurfaceInfo*)dsi->platformInfo;
[$[Get Code]]
Rerun:
ant clean
ant -DARCH=x86_64
[$[Get Code]]
That seemed to do it! jna.jar is created.
Test failures:
Not all the tests pass:
[junit] Testcase: testLoadJAWT(com.sun.jna.LibraryLoadTest): Caused an
ERROR
[junit] Can't load JAWT
[junit] java.lang.UnsatisfiedLinkError: Can't load JAWT
[junit] at com.sun.jna.Native.getWindowHandle0(Native Method)
[junit] at com.sun.jna.Native$AWT.getComponentID(Native.java:1766)
[junit] at com.sun.jna.Native$AWT.getWindowID(Native.java:1742)
[junit] at com.sun.jna.Native.getWindowPointer(Native.java:262)
[junit] at com.sun.jna.LibraryLoadTest
$AWT.loadJAWT(LibraryLoadTest.java:169)
[junit] at
com.sun.jna.LibraryLoadTest.testLoadJAWT(LibraryLoadTest.java:42)
[junit]
[junit]
[junit] Testcase:
testLoadLibraryWithUnicodeName(com.sun.jna.LibraryLoadTest): FAILED
[junit] Expected JNA native library at /Users/cxh/src/jna/build-d64/
native/libjnidispatch.dylib \
is missing
[junit] junit.framework.AssertionFailedError: Expected JNA native
library at /Users/cxh/src/jna/\
build-d64/native/libjnidispatch.dylib is missing
[junit] at
com.sun.jna.LibraryLoadTest.testLoadLibraryWithUnicodeName(LibraryLoadTest.java:
9
6)
I'm not sure about the above.
[junit] Testcase: testLaunchedUnderWebStart(com.sun.jna.WebStartTest):
Caused an ERROR
[junit] javaws executable not found
[junit] java.io.IOException: javaws executable not found
[junit] at com.sun.jna.WebStartTest.findJWS(WebStartTest.java:296)
[junit] at
com.sun.jna.WebStartTest.runTestUnderWebStart(WebStartTest.java:151)
[junit] at
com.sun.jna.WebStartTest.runTestUnderWebStart(WebStartTest.java:253)
[junit] at com.sun.jna.WebStartTest.runBare(WebStartTest.java:370)
Oddly, javaws is in my path?
_Christopher