# CM9 won't build on Mac OS X Lion



## ArmanUV (Feb 1, 2012)

edit: I derped this post. The original question was about cm9 building errors on mac os x lion. 
I solved my problem and wrote a detailed guide here: http://rootzwiki.com/topic/25493-guide-compiling-cyanogenmod-9-on-mac-os-x-lion/


----------



## jocelyn (Jul 22, 2011)

Hi,

Ok, so, if you've done any google searching, you've probably found a ton of conflicting information on how to compile CM7 on mac. So far, it seems that CM9 is basically the same, just with some slightly different steps in the environment setup. One thing to note is that while AOSP is supposedly able to build fine using all the standard OSX toolchain from 10.6 up, CM7 wouldn't.

Now, I haven't actually bothered to waste the 60-90 minutes it takes my laptop to compile a full CM rom yet, but I do have the source synced, and I compile theme engine themes and kernels/recoveries from it. And coming from building CM7, unless a ton of dependencies have changed, there should be a lot of other tools you need in order to compile on mac. You probably want/need to brew install:

```
coreutils, e2fsprogs, exiftool, libiptcdata, sdl
```
though the SDL dependency used to be tied to the qemu, so its possible its not necessary anymore if you follow the advice below and comment out the entire qemu makefile. I just haven't bothered to remove SDL and try it yet.

Also, though it's backwards from the android website, make sure /usr/local/bin is before /usr/bin and /bin in your $PATH, else your gnu binaries won't be used even if you symlink them in /usr/local/bin. And while checking that, for CM7, I had to use gnu-sed, gnu-find, and gnu-readlink to compile successfully on mac. Don't just symlink all the gnu core utils though, CM7 used to fail if gnu-stat was used instead of the OSX stat binary. I just wrote a quick script that does this for me, checks the symlinks, and creates/deletes them if necessary, and I use it inside an alias to setup my build environment.


```
<br />
for L in "sed" "find" "readlink"<br />
do<br />
	dir="/usr/local/bin"<br />
	if [[ ! -L $dir/$L ]]; then<br />
		echo "linking gnu-$L as $L..."<br />
		cp -R "$dir/g$L" "$dir/$L"<br />
	fi<br />
done<br />
<br />
if [ -L /usr/local/bin/stat ]; then<br />
	echo "restoring OSX stat binary..."<br />
	rm /usr/local/bin/stat<br />
fi<br />
```
Next, you need to comment out all the lines in the qemu make file: /system/external/qemu/Android.mk

And if you run lion/10.7, double-check that the strnlen definition in elfutils is commented out: /system/external/elfutils/config-compat-darwin.h
(though this seems to be setup properly by default in the cm9 source.)

Also, if you have Xcode 4.3.x, you need to setup the command line path to the developer tools, since they're inside the Xcode.app package now:

```
sudo xcode-select -switch /Applications/Xcode.app
```
And then symlink the SDK's to their old location:
Make the directory if it doesn't exist:

```
sudo mkdir -p /Developer/SDKs
```

And now link the SDKs

```
<br />
cd /Developer/SDKs<br />
ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk MacOSX10.6.sdk<br />
ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk MacOSX10.4u.sdk<br />
```

And if you don't have a version of xcode 3.6 to grab the 10.5 SDK from, then you need to create a symlink for it too:

```
<br />
ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk MacOSX10.5.sdk<br />
```

However, you can actually find an installer for just the 10.5 SDK here if you want to install it into /Developr/SDKs (its only ~200MB, so I installed it)
http://www.modaco.co...m-on-os-x-lion/

OK, lastly, a couple notes!

I don't have any newer/duplicate version of gcc/g++ installed, and it compiles fine for me with the default 4.2.1
I don't bother to brew install (g)make either, since Xcode includes make @ 3.81 already

Anyway, hope this helps. I have a CM9 build going right now to test my setup, and its been running for ~40 minutes without error. I'll update the post when it either errors, or completes successfully.

EDIT: ran into the same error you had, going to try some things for a few minutes before bed, if it doesn't fix it, I'll try and debug tomorrow.

Cheers


----------



## ArmanUV (Feb 1, 2012)

jocelyn said:


> Hi,
> 
> Ok, so, if you've done any google searching, you've probably found a ton of conflicting information on how to compile CM7 on mac. So far, it seems that CM9 is basically the same, just with some slightly different steps in the environment setup. One thing to note is that while AOSP is supposedly able to build fine using all the standard OSX toolchain from 10.6 up, CM7 wouldn't.
> 
> ...


thank you for the detailed answer jocelyn. 
I figured out my main problem: Xcode 4.3 . The switch to llvm screws everything up. I tried gcc-4.7 and symlinking it into PATH with no luck. I finally gave up and used the os x gcc installer and it worked like a charm. Symlinking the SDKs seems like a nice alternative. it's kinda weired that it compiles with gcc 4.2 though. I always though 4.2 had very basic support for c++, guess I was wrong. 
Symlinking sed/coreutilities turned out to be unnecassary, but I guess it doesn't hurt anything.

Please read my guide, linked in OP, and comment if you find anything out of order.


----------

