Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install GMP library on Mac OS X 10.9 and Xcode

Tags:

c++

xcode

macos

gmp

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?

like image 769
Matteo Monti Avatar asked Aug 17 '14 07:08

Matteo Monti


2 Answers

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.

like image 155
Brett Hale Avatar answered Sep 17 '22 03:09

Brett Hale


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.

like image 28
trojanfoe Avatar answered Sep 20 '22 03:09

trojanfoe