Using GMP in Xcode 4 With the Help of GMPInt

One of the issues I have run into trying to solve some of the Project Euler questions is that some of the numbers are too big for any of the Objective-C primitives. Some Googling shows that GMP is the answer to my problems but being a pretty novice programmer I have had issues making it work, that is until I found GMPInt, an Objective-C wrapper for GMP.

Setup went pretty smooth following the instructions on the GMPInt Github page but there were a few issues. Here is the steps it took for me to get it to work: 

  1. Install Homebrew
  2. Run the command “brew install gmp” in Terminal, having sudo infront of that command gave me an error about being cowardly, but dropping sudo made it run fine
  3. Add the libgmp.dylib file to your project under Target > Build Phases >Link Binary with Libraries
  4. From there I had to correct the line ‘#import “/usr/local/Cellar/gmp/5.0.1/include/gmp.h”‘ to 5.0.5 as that was the version of GMP I had installed
  5. I also had to go through the GMPInt.m file and comment out any autorelease/release references as I selected ARC for the test project I made

From there I setup a simple test and ran the app, worked perfectly, now I can attempt some of the Project Euler problems I couldn’t before.