简体   繁体   中英

Install GMP library on Mac OS X 10.9 and Xcode

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?

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.

将Xcode项目设置中的标题搜索路径库搜索路径分别设置为/usr/local/include/usr/local/lib ,因为默认情况下,Xcode不会搜索这些路径。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM