Forcing i386 architecture in Xcode 4.0.2 SDK

So I decided to upgrade to the new Xcode SDK on my Mac. And I did it during the weekend just in case something go wrong. And of course, something went wrong [Note: I’m not going to rant about the new Xcode interface. I just don’t like it. That’s it.]

Anyways, it seems the new SDK (Xcode 4.0.2) does not include the old gcc 4.0 compiler anymore. Instead, we’re left with gcc 4.2 which is optimized for 64bits compiling. The problem is that Crimild and some of the third-party libraries that I’m using do not yet support 64bits. I knew about this beforehand and my mistake was to trust that there will be no side-effect after the upgrade.

It turns out that after installing the new SDK, all sources files were built for the x86_64  architecture instead of i386, even when my CMake configuration was forcing a specific configuration:

SET ( CMAKE_CXX_COMPILER /usr/bin/g++-4.2 )
SET ( CMAKE_C_COMPILER /usr/bin/gcc-4.2 )

After a lot of try and error (and a little bit of reading), a verbose make all process indicated that the -arch i386 compiler flag was correctly set at compile time, but there was no sign of it in the link phase. Then, I changed CMake to look like this:

SET ( CMAKE_CXX_COMPILER /usr/bin/g++-4.2 )
SET ( CMAKE_CXX_FLAGS “-arch i386” )
SET ( LINK_FLAGS “-arch i386” )
SET ( CMAKE_C_COMPILER /usr/bin/gcc-4.2 )

It seems a little bit redundant to me, but then again, this is the configuration that worked on both Eclipse and the Terminal. So I changed the CMakeLists.txt file with the new flags, cleaned up the CMake cache and regenerate the Makefiles. And everything worked again and all developers lived happily ever after (or at least until July, when the next SDK comes out).

I’m not sure if other people had the same issue (I couldn’t find anything relevant out there), so I’m leaving this here just in case someone needs it. Guys at Google, I know you’re reading this 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s