Trying to build OpenJDK 9 for iOS x86_64
Bob Vandette
bob.vandette at oracle.com
Wed Jan 20 13:57:33 UTC 2016
It’s not sufficient to modify the binaries generated in order to update the min os version since the
Xcode header files have many ifdefs that take alternate paths when building for iOS and as
you’ve seen, our build does the same.
As documented in the Java SE build instructions, you need a copy of the cups header files
for the build in addition to freetype, libffi and XQuartz for a few X11 header files.
We use a script that automates the generation of the configure command.
The next time I update the iOS instructions, I’ll provide more detailed
configure instructions.
Here’s a configure command that I used a while ago. You’ll have to update the
paths to point to your local copied of Xcode, JDK, freetype and cups headers.
Let me know if this doesn’t work for you and I’ll investigate.
/Users/bvandett/ws/jdk9dev-test/configure --enable-option-checking=fatal --build=x86_64-apple-darwin14.1.0 --host=x86_64-macos-ios --target=x86_64-macos-ios --disable-warnings-as-errors --disable-headful --with-boot-jdk=/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home --with-jdk-variant=normal --with-jvm-variants=minimal1 --enable-static-build=yes --with-extra-cflags=-Wno-implicit-function-declaration -Wno-unused-parameter -miphoneos-version-min=8.0 --with-extra-cxxflags=-Wno-implicit-function-declaration -Wno-unused-parameter -miphoneos-version-min=8.0 --with-extra-ldflags=-miphoneos-version-min=8.0 -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/system --with-cups-include=/java/devtools/share/cups/include/ --with-sys-root=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk --with-tools-dir=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/../../usr/bin --with-debug-level=release --disable-precompiled-headers --with-freetype-lib=/usr/local/lib --with-freetype-include=/usr/local/include/freetype2
Bob.
> On Jan 20, 2016, at 4:15 AM, Andreas Vigneront <andreasvigneront at gmail.com> wrote:
>
> Hi,
>
> I've been trying to get OpenJDK 9 to compile for iOS x86_64 (so a simulator
> build), using the latest forest at hg.openjdk.java.net/mobile/dev/. I ran
> into a couple of issues and hope you can help me resolve them.
>
> Here's how I build things:
>
> hg clone http://hg.openjdk.java.net/mobile/dev/
> cd dev
> ./get_sources.sh
> ./configure --openjdk-target=x86_64-macos-ios --with-boot-jdk=$JAVA_HOME
> --disable-warnings-as-errors --disable-headful --enable-static-build=yes
> --with-jvm-variants=minimal1
>
> This is essentially based on one of the earlier mailing list posts. After
> installing FreeType via brew, this compiles without a problem and i end up
> with static libraries in the build/ directory.
>
> I then created a simple iOS project in Xcode, linking the static libs to
> the binary, and including the jdk/include directory in the search paths. I
> use some standard JNI code to initialize the VM just to have the linker
> pull in symbols from the static libs. However, when linking, i get the
> following error:
>
> /Users/andreas/workspace/openjdk9-mobile/build/ios-x86_64-normal-minimal1-release/jdk/lib/amd64/minimal/libjvm.a(jni.o),
> building for iOS simulator, but linking in object file built for OSX, for
> architecture x86_64
>
> The build has two issues it turns out:
>
> 1) To resolve the linker issue, one has to pass
> "-miphoneos-version-min=6.0" (or a higher version) to Clang. The Mach-O
> object files will then have the proper load command denoting the target OS
> and minimum version.
>
> 2) The build should use the proper sysroot, e.g.
> "-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk".
> This will ensure that the native bits of the build actually use the proper
> frameworks.
>
> I tried to fix issue 1. by passing the minimum iOS version with
> --with-extra-cflags/--with-extra-cxxflags. However, then the build fails
>
> "configure: error: C compiler cannot create executables"
>
> Since the binaries are the same for x86_64 Mac OS X builds (what the
> OpenJDK build generates) and iOS Simulator builds, i simply fixed up all
> object files with a little tool i wrote, replacing the minimum OS load
> command.
>
> When i link these modified binaries, i get a lot of undefined symbols which
> are not available in the iOS SDK:
>
> _finite
> _opendir$INODE64
> _readdir$INODE64
> _readdir_r$INODE64
>
> I checked the files that use these functions, e.g. os_bsd.c to figure out
> what's wrong. It appears the calls to these functions are actually
> #ifdef'ed out when passing TARGET_OS_IPHONE. It appears the autoconf output
> generated by the above configure call doesn't add this to CFLAGS/CXXFLAGS.
>
> Finally, i tried passing the proper sysroot to configure. That fails
> because iOS doesn't support cups.
>
> I saw that Gluon had a working OpenJDK build for the simulator, so i must
> be doing something wrong. It'd be awesome if you could point out my errors
> :)
>
> Best,
> Andreas
More information about the mobile-dev
mailing list