Linker trouble again. For me it’s always the linker, never the compiler. In the context of something or other (haven’t investigated details yet, I hope I can fix this without anything as laborious), this comes up:
"cputype (18, architecture ppc) does not match cputype (7) for specified -arch flag"
OK, a bit of context: I’m trying to build a universal binary by invoking a setup.py script. I think the problem is that in the process some lib is linked in, and because I’m building a fat binary, the lib is expected to be fat, too, but isn’t. Now, it’s not that I want to build a universal binary. I’m not making a binary package that should be fit for redistribution, I just want this for myself. Hence, I could do with a PPC only build, but where can I specify this?
Grepping for “arch” or “i386” yields nothing. I’ve always thought that kilometre-long Makefiles are evil, but setuptools or ez_install or whatever it’s called isn’t quite the Egg of Columbus either. It’s supposed to be as easy as invoking the setup script first with the parameter ‘build’, then ‘install’, but when that doesn’t work, I just have no clue what’s what and where to find stuff.
However, in this ancient discussion from some mailing list, I’ve found a nifty clue:
from distutils.sysconfig import get_config_vars
print get_config_vars('CC', 'LDSHARED')
import os
print os.environ.get('LDFLAGS')
AHA, so this, then, is the kernel of the brute! The latter invocation gives me nothing, but the former turns up
['gcc', 'gcc -arch i386 -arch ppc …
']
Now, how do I temporarily get rid of the i386 flag so I can build my PPC-only binary? Where does the configuration information come from? The
documentation of distutils’s sysconfig module has the answer:
>>> from distutils.sysconfig import get_makefile_filename
>>> get_makefile_filename()
'/Library/Frameworks ... python2.4/config/Makefile'
So there
is a
Makefile involved, after all; you just have to know where to look. In there, I temporarily removed the i386 flag from
BASECFLAGS and
LDFLAGS, and the build went without a problem.
So, there’s one way to deal with the above-mentioned error message, hereby made public to be indexed by seach engines for posterity. And we’ve learned something about setuptools as well; life is good.