Folks (probably Brad and Al in particular),
I just came across this posting on a Darwin list. It describes some
of the tricky steps in building (or assembling, I haven't read it
quite so closely) an x86 JNI library on a PPC Mac. I'm logging it
here just in case it's useful.
See you,
Norman
From: Paul Archibald <[log in to unmask]>
Date: 2006 May 22 20.19.36 BDT
To: Eric Albert <[log in to unmask]>
Cc: [log in to unmask]
Subject: Re: compile for i86 on my PPC?
Eric, and all,
Sorry this has taken a while to respond to, but I wanted to have
something useful to say.
I finally got this working pretty nicely. I can use the same code and
makefile on either my tiPowerbook (PPC) or my loaner IntelMini, build
and link and run the JNI lib, and it seems to work fine. This is
good. Thanks to you guys for your help. Oh, yeah, I also figured out
how to do it as a universal binary, which is a definite good.
(Our application, written in Java, loads a JNI lib that does math
functions for us. One interesting feature of the JNI is that it
compiles the user's inputted expressions into assembly language and
executes that code on the fly. I had some headscratching to do when
we started the Intel thing, since we could no longer assume that all
Macs were running PPC (we already had x86 code generating for the
Windows version). This made it necessary to rework the makefile, as
well as changing around some of the preprocessor directives.)
Here is the compile/link part (which does the ppc/x86 universal thing
I am so happy about, note that there are 2 -arch options):
$(TARGET): $(OBJECTS)
g++ -arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk -
o $@ -dynamiclib -install_name $(DESTDIR)/$@ $^
strip -x $@
%.o: %.cpp
g++ -arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk -
c -O2 -o $@ $^ -I /System/Library/Frameworks/JavaVM.framework/Headers
I had some trouble getting the output to work on the machine that the
lib was not built on, so the lib build on the PPCPowerbook would not
work on the IntelMini The solution was to be sure that the code
generation line in the makefile used the universal SDK
(MacOSX10.4u.sdk), as well as the liker line. I think this is the
main lesson to learn: If you want a universal jni, compilable on
either platform, amke sure you have the universal SDK included for
both the compiler and linker.
Thanks to Eric and Kevin.
Paul Archibald
A society of sheep must in time beget a government of wolves.
-- Henry de Jouvenel
On May 5, 2006, at 1:22 PM, Eric Albert wrote:
> Specifically, you'll want to pass the -arch flags and -isysroot to
> the compiler, like this:
>
> $(TARGET): $(OBJECTS)
> g++ -arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk
> -o $@ -dynamiclib -install_name $(DESTDIR)/$@ $^
> strip -x $@
>
> %.o: %.cpp
> g++ -arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk
> -c -O2 -o $@ $^ -I /System/Library/Frameworks/JavaVM.framework/Headers
>
> Hope this helps,
> Eric
>
> On May 5, 2006, at 1:12 PM, Kevin Van Vechten wrote:
>
>> Yes, you can use the -arch argument with gcc or g++, i.e.:
>> g++ -arch i386 -arch ppc -arch ppc64 ...
>>
>> Will build for all three architectures.
>>
>> You'll need to be sure to build on a system with universal
>> libraries so the link phase will succeed. I don't know whether
>> they encompass JNI, but usually you'll want to use the 10.4u.SDK
>>
>> For more details:
>>
>> <http://developer.apple.com/technotes/tn2005/tn2137.html>
>>
>> <http://developer.apple.com/opensource/
>> buildingopensourceuniversal.html>
>>
>> - Kevin
>>
>> On May 5, 2006, at 1:05 PM, Paul Archibald wrote:
>>
>>> Our Java app uses a JNI lib for mathematical calculations. We
>>> build the JNI with GCC with a makefile.
>>>
>>> Since we entering the IntelMac age, we need to target our JNIs to
>>> both the i86 and PPC architectures. I am doing it now by building
>>> the i86 JNI on an intelMini, and the PPC JNI on my PPC powerbook.
>>>
>>> My question is this: can I build for a different architecture
>>> than that of the machine doing the compiling? I would like to be
>>> able to build both the PPC and i86 libs on whatever machine I
>>> have handy. Is there a g++ option to force which architecture is
>>> output? I am not very experienced with makefiles.
>>>
>>> Here is part of my makefile:
>>>
>>> $(TARGET): $(OBJECTS)
>>> g++ -o $@ -dynamiclib -install_name $(DESTDIR)/$@ $^
>>> strip -x $@
>>>
>>> %.o: %.cpp
>>> g++ -c -O2 -o $@ $^ -I /System/Library/Frameworks/
>>> JavaVM.framework/Headers
>
|