Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to link ppc after upgrading to XCode 4

I followed these instructions on how to get the 10.4 SDK working with PPC after upgrading to XCode 4. I am able to compile, but it errors out at link time.

As an added wrinkle, I'm not using XCode per se, but the gcc toolchain that comes with it. (This is part of a large cross-platform project that uses makefiles.)

Here's a sample makefile:

CXX=g++-4.0
CXXFLAGS=-arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4

helloworld: helloworld.o
    $(CXX) $^ -o $@ $(CXXFLAGS)

with a helloworld.cpp:

#include <stdio.h>

int main(void) {
    printf("hello world \n");
    return 0;
}

and here's its output:

$ make
g++-4.0 -arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4   -c -o helloworld.o helloworld.cpp
g++-4.0 helloworld.o -o helloworld -arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4
ld: in /Developer/SDKs/MacOSX10.4u.sdk/usr/lib/crt1.o, in section __TEXT,__text reloc 1: sectionForNum(4) section number not for any section for architecture ppc
collect2: ld returned 1 exit status
lipo: can't open input file: /var/folders/NK/NK2TdejFFfOupEszIr4fG++++TM/-Tmp-//ccryAbut.out (No such file or directory)
make: *** [helloworld] Error 1

btw, this exact makefile works fine on an XCode 3 system.

like image 938
paleozogt Avatar asked Mar 23 '11 18:03

paleozogt


1 Answers

Since you are using the command line gcc (Unix Development Package), not the GCC of /Developer or /Xcode3 will be used, but the one of /usr, which I have not touched my original description. To restore PPC support to the command line GCC, you'll have to do at least what jas pointed out in this answer. Or you to alter your Makefile to use the gcc from /Developer instead (I created your helloworld.cpp in the current working directory before executing those commands):

$ /Developer/usr/bin/g++-4.0 -arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4   -c -o helloworld.o helloworld.cpp
$ /Developer/usr/bin/g++-4.0 helloworld.o -o helloworld -arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4
ld: warning: object file compiled with -mlong-branch which is no longer needed. To remove this warning, recompile without -mlong-branch: /Developer/SDKs/MacOSX10.4u.sdk/usr/lib/crt1.o
ld: warning: object file compiled with -mlong-branch which is no longer needed. To remove this warning, recompile without -mlong-branch: /Xcode3/usr/bin/../lib/gcc/powerpc-apple-darwin10/4.0.1/crt3.o
$ ./helloworld 
hello world 

You can safely ignore the two warnings. Unfortunately GCC 4.0 does not support the -mno-long-branch, which would be necessary to avoid long branches.

like image 105
Mecki Avatar answered Nov 07 '22 17:11

Mecki