5

My question is as simple as the title. I have a Macbook Pro with OS X Mavericks (10.9.4) and Xcode (5.1.1). I need to install the GMP arbitrary precision libraries so that I can just get to write GMP-enabled programs from within Xcode.

  • I downloaded the package from the official website
  • I extracted it to my desktop
  • ./configure --prefix=/usr/local --enable-cxx
  • make
  • make check
  • sudo make install

But when I go to Xcode and just #include <gmpxx.h> it doesn't find it. Also adding -lgmp to my linker flags causes an error.

I also tried using homebrew with brew install gmp but that didn't work either (same symptohms)

What is the correct way to solve this problem?

Matteo Monti
  • 8,362
  • 19
  • 68
  • 114

2 Answers2

7

You need to ensure that you have an include path -I/usr/local/include, before you can include <gmpxx.h> (or <gmp.h> for that matter).

Also, adding -lgmp is insufficient, since that's only the C interface. You want to link with -lgmpxx (the C++ library), and possible specify the path to that library with -L/usr/local/lib.

You can run otool -L /usr/local/lib/libgmpxx.dylib, to ensure that libgmp.dylib is already linked to it. Which it should be.

Brett Hale
  • 21,653
  • 2
  • 61
  • 90
  • thanx. this helped. also i checked this link http://stackoverflow.com/questions/14134064/how-to-set-include-path-in-xcode-project to know how to add include path – vishnu viswanath Oct 10 '15 at 01:00
1

Set the Header Search Path and Library Search Path in the Xcode Project Settings to /usr/local/include and /usr/local/lib respectively as, by default, these paths are not searched by Xcode.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242