在 Mac OS X 10.9 和 Xcode 上安装 GMP 库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25347054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Install GMP library on Mac OS X 10.9 and Xcode
提问by Matteo Monti
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.
我的问题和标题一样简单。我有一台装有 OS X Mavericks (10.9.4) 和 Xcode (5.1.1) 的 Macbook Pro。我需要安装 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
- 我是从官网下载的包
- 我把它解压到我的桌面
./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.
但是当我去 Xcode 时,#include <gmpxx.h>
它没有找到它。还将 -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?
解决这个问题的正确方法是什么?
回答by Brett Hale
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).
您需要确保您有一个包含路径-I/usr/local/include
,然后才能包含<gmpxx.h>
(或<gmp.h>
就此而言)。
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
.
此外,添加-lgmp
是不够的,因为那只是 C 接口。您想要链接-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. Which it should be.
您可以运行otool -L /usr/local/lib/libgmpxx.dylib
, 以确保libgmp.dylib
已链接到它。应该是哪个。
回答by trojanfoe
Set the Header Search Pathand Library Search Pathin the Xcode Project Settings to /usr/local/include
and /usr/local/lib
respectively as, by default, these paths are not searched by Xcode.
将Xcode Project Settings 中的Header Search Path和Library Search Path分别设置为/usr/local/include
和/usr/local/lib
,因为默认情况下,Xcode 不会搜索这些路径。