Can I compile universal code using Macports' GCC?
Asked Answered
A

2

5

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.

Avernus answered 14/12, 2011 at 0:5 Comment(0)
L
3

You can combine binaries with different architectures in to a single universal using lipo.

Laubin answered 14/12, 2011 at 0:51 Comment(1)
Thanks that works. I didn't know there's lipo, I guess all I really need is lipo. I need to change some of my Makefiles to stop the arch flags and use lipo to produce universal code now :)Avernus
H
6

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

Hydnocarpate answered 2/3, 2012 at 8:20 Comment(0)
L
3

You can combine binaries with different architectures in to a single universal using lipo.

Laubin answered 14/12, 2011 at 0:51 Comment(1)
Thanks that works. I didn't know there's lipo, I guess all I really need is lipo. I need to change some of my Makefiles to stop the arch flags and use lipo to produce universal code now :)Avernus

© 2022 - 2024 — McMap. All rights reserved.