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: translating a build script for JNI for linux to JNI for OS X



Stephyn Butcher wrote:

I'm trying to compile a JNI wrapper for a third party library. The
source code for the JNI wrapper exists as does a build file but it's
for linux. Additionally, the compiled binaries for the actual code
exist for OS X.

However, I cannot even begin to figure out how to make this work on OS
X. I have the following command:

echo compiling JNI wrapper
g++ -O3 -DNDEBUG -feliminate-unused-debug-symbols -fpic -s -shared -o
libjsmile.so ../*.cpp -I$JINC -I$JINC/linux -I../cppsmile -L../
cppsmile -lsmilearn -lsmile

and I don't know how to translate it into OS X speak.

What architectures do you need to build for? OS X runs on ppc, i386 and x86_64. You can either build the libraries independently for each architecture and merge them into a Universal Binary using lipo, or try and build it as universal from the get go. I have found with Unix ports that the lipo approach is easier. To build for a specific architecture, add the argument "-arch XXX" (e.g. "-arch ppc", "-arch i386" or "-arch x86_64") to the command line. I don't use lipo, since we distribute using Java Web Start and can determine the architecture up front and provide just the lib tailored to the platform in use. See "man lipo", or search the list archives for examples of its usage.


You will also need to link with either a universal version of the native "smile" libs, or one tailored to the architecture you are building for. If you have a universal binary for libsmilearn and libsmile your command line should work as-is to link with them. If you have separate binaries, you'll need to change the "-:../cppsmile" argument to locate the desired version.

The standard JNI library name on OS X is "libXXX.jnilib", or "libXXX.dylib" (10.5+ only, IIRC). The command line needs to be changed from "-o libjsmile.so" to "-o libjsmile.jnilib". The "libXXX.jnilib" naming works on all versions of OS X.

I have added a "-install_name libXXX.jnilib" in my builds. It is probably not required, since Java finds and loads the JNI libs itself rather than depending on dyld to do so using the standard OS X search paths.

You will need to specify where the JNI headers are located as the value of variable JINC. This should be something like /System/Library/ Frameworks/JavaVM.framework/Versions/CurrentJDK/Headers. The "-I$JINC/ linux" argument can be removed.

I use "-dynamiclib" instead of "-shared", I suspect the distinction between these is semantically null.

I have also added "-compatibility_version 1 -current_version 1 - mmacosx-version-min=10.4 -Wl,-single_module" to be pedantically correct.

Since I build my JNI libs using the Mac OS X SDKs installed with Xcoode (i.e. frameworks and headers installed under /Developer/SDJs/ MacOSX10.*.sdk/...) rather than the "live" system versions to build backwards compatible binaries (some go back as far as OS X 10.2.8). To support that I have added -I -L and -F parameters to override the live system locations.

I also add "-fmessage-length=0" to format error output the way I like.


_______________________________________________ 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.