Since Apple do not support GCC 4.6 or GCC 4.7, I just switched to MacPorts' build of GCC 4.6/4.7. However, I had a problem to build my code in "Universal" architecture.
Traditionally, I'd do g++ -arch i386 -arch x86_64 ...
to compile my binary for at least i386/x86_64 architecture. I did some search, and realised that -arch option is only supported by apple's compilers. So of course it didn't work with the Macports'. The best I could do is use -m32
/-m64
options to specify an architecture I want. However, this will only produce a binary eitherr in i386 or x86_64 format. What I really want is get a binary file in both architecture (Universal) just as been done with the original GCC compilers.
Is this not supported or a known problem? I have tried the whole night looking for answers on Google, but I haven't get anything useful. So I just start doubt if I am the only one had this problem and I have missed something really important to get it work? Really appreciate if anyone can give me some suggestions.
BTW. I have installed gcc46 +universal
variants, but it didn't produce anything really universal except compiling separate binaries for each architecture.
Xing.
Oh, I just had this problem and spent a pretty extensive amount of time on it. It turns out that the apple version of GCC 4.2.1 is really just a wrapper that honors a few flags (notably the -arch flag) and then uses lipo to stick the object files back together into a fat object. I modified this driver a bit so that it would wrap macports GCC while still honoring the -arch flag and produce multi arch object files (for 32 bit and 64 bit intel anyway).
I just posted a fairly extensive write up on how to do this:
http://thecoderslife.blogspot.com/2015/07/building-with-gcc-46-and-xcode-4.html
You can combine binaries with different architectures in to a single universal using lipo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With