开发者

Cross-compiling for PPC G3 with MacOS 10.3.9

I am writing a program to talk to a USB hardware interface board, which requires a small JNI library. I am running 10.5.8 on my compile machine, and can succesfully compile the shared library for JNI with the following commands:

# Build shared library for K8055
g++ -x objective-c -fmessage-length=0 -pipe -Wno-trigraphs \
    -fpascal-strings -fasm-blocks -O0 -mdynamic-n开发者_JAVA技巧o-pic -fvisibility=hidden -gdwarf-2 \
    -Wmost -Wno-four-char-constants -Wno-unknown-pragmas \
    -c ./K8055/K8055.m \
    -o ./K8055/K8055.o \
    -arch x86_64 \
    -arch i386

echo "Building JNI shared library..."
gcc -c -m64 -I/System/Library/Frameworks/JavaVM.framework/Headers \
    k8055usbio.m -o k8055usbio.so -arch x86_64

echo "Compiling dynamic library with both..."
g++ -m64 -dynamiclib -o ./lib/libk8055usbio.dylib \
    k8055usbio.so ./K8055/K8055.o\
    -framework Foundation -framework IOKit

I don't really understand what I'm doing here; I have managed to piece that together from a lot of Googling. My question is: How do I modify this to compile for a PPC G3 machine running 10.3.9? The Java part I am happy with. Here is what I've tried so far:

# Build shared library for K8055 (PPC)
echo "Building driver shared library..."
g++ -x objective-c -fmessage-length=0 -pipe -Wno-trigraphs \
    -fpascal-strings -fasm-blocks -O0 -mdynamic-no-pic -fvisibility=hidden -gdwarf-2 \
    -Wmost -Wno-four-char-constants -Wno-unknown-pragmas \
    -c ./K8055/K8055.m \
    -o ./K8055/K8055.o \
    -arch ppc

echo "Building JNI shared library..."
gcc -c -I/System/Library/Frameworks/JavaVM.framework/Headers \
    k8055usbio.m -o k8055usbio.so -arch ppc

echo "Compiling dynamic library with both..."
gcc -shared -fPIC -o ./lib/libk8055usbio.dylib k8055usbio.so \
    ./K8055/K8055.o -framework Foundation -framework IOKit  -arch ppc

But when I try to System.load() it, I get the following error from the Java (1.5) program:

dyld: java bad CPU subtype in library: /libk8055usbio.dylib
Trace/BPT trap

I don't have any idea how to fix it, what CPU subtype should I be specifying?


You'll need to fiddle a couple of options. First, you'll want to explicitly specify an SDK using -isysroot, since newer SDKs will subvert you in various ways. Second, you'll want to pass -mmacosx-version-min=10.3 to indicate that you really want to run on 10.3. Using both of those options on a little test program, I get a binary that claims it ought to run on a G3. Here's my command line:

gcc-4.0 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk/ -mmacosx-version-min=10.3 -o testprog testarch.c

You can sanity check the CPU type/subtype in the header using otool -h, which for this example gives me:

$ otool -h testprogtestprog:
Mach header
      magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
 0xfeedface      18          0  0x00          2    11       1268 0x00000085

The zero there is CPU_SUBTYPE_POWERPC_ALL, per /Developer/SDKs/MacOSX10.4u.sdk/usr/include/mach/machine.h .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜