简体   繁体   English

在Mac OS X 10.9和Xcode上安装GMP库

[英]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). 我有一个Mac OS Pro OS X Mavericks(10.9.4)和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. 我需要安装GMP任意精度库,以便我可以从Xcode中编写支持GMP的程序。

  • 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. 但是当我去Xcode并且#include <gmpxx.h>它找不到它。 Also adding -lgmp to my linker flags causes an error. 将-lgmp添加到我的链接器标志会导致错误。

I also tried using homebrew with brew install gmp but that didn't work either (same symptohms) 我也尝试过使用brew install gmp自制软件,但是也没用(同样的症状)

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). 在包含<gmpxx.h> (或<gmp.h> )之前,您需要确保包含一个包含路径-I/usr/local/include

Also, adding -lgmp is insufficient, since that's only the C interface. 另外,添加-lgmp是不够的,因为那只是C接口。 You want to link with -lgmpxx (the C++ library), and possible specify the path to that library with -L/usr/local/lib . 您想要链接-lgmpxx (C ++库),并且可以使用-L/usr/local/lib指定该库的路径。

You can run otool -L /usr/local/lib/libgmpxx.dylib , to ensure that libgmp.dylib is already linked to it. 您可以运行otool -L /usr/local/lib/libgmpxx.dylib ,以确保libgmp.dylib已经链接到它。 Which it should be. 它应该是什么。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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