[英]Installing GMP on MacOS X with Xcode
I'm trying to use the GMP library in my C and C++ programs. 我正在尝试在我的C和C ++程序中使用GMP库。 I do code using the Xcode. 我使用Xcode编写代码。 I followed the instructions to install the GMP on my machine and I end up with a folder "~/usr/local/gmp-5.0.5" which contains the gmp.h file. 我按照说明在我的机器上安装GMP,最后得到一个包含gmp.h文件的文件夹“〜/ usr / local / gmp-5.0.5”。
How can I make my programs to see this library? 如何让我的程序看到这个库? if I decided to save my programs on desktop for example??? 如果我决定将我的程序保存在桌面上,例如???
Where is the best place to install the gmp-5.0.5??? 安装gmp-5.0.5的最佳位置在哪里? Using include "gmp.h" will show the error "file not found". 使用include“gmp.h”将显示错误“找不到文件”。
I have done it this way: 我这样做了:
Download GMP from https://gmplib.org/ (gmp-6.0.0a.tar.lz) Download lzip from http://www.nongnu.org/lzip/lzip.html (lzip-1.16.tar.gz) 从https://gmplib.org/下载GMP(gmp-6.0.0a.tar.lz)从http://www.nongnu.org/lzip/lzip.html下载lzip(lzip-1.16.tar.gz)
If you install the library in /usr/local
, you will be able to simply #include <gmp.h>
and add -lgmp
to your linker settings (Linking > Other Linker Flags). 如果在/usr/local
安装库,则可以简单地#include <gmp.h>
并将-lgmp
添加到链接器设置(链接>其他链接器标志)。
If you insist on putting the library in your home directory, say ~/local
, then you will need to add ~/local/include
to your header search paths (Search Paths > Header Search Paths), ~/local/lib
to your library search paths (Search Paths > Library Search Paths). 如果您坚持将库放在主目录中,比如说~/local
,那么您需要将~/local/include
添加到标题搜索路径(搜索路径>标题搜索路径), ~/local/lib
到您的库搜索路径(搜索路径>库搜索路径)。 These are under the project or target settings. 这些是在项目或目标设置下。 You will also need to add -lgmp
as above. 您还需要添加-lgmp
,如上所述。
Note about architectures: LibGMP is rather unique in that it will choose the target architecture at compile-time, and it usually chooses a 64-bit target where available. 关于体系结构的注意事项: LibGMP非常独特,因为它将在编译时选择目标体系结构,并且通常在可用时选择64位目标。 If your project is 32-bit and your GMP is 64-bit, linking will fail. 如果您的项目是32位且GMP是64位,则链接将失败。
LibGMP does this because the kind of operations it does are much faster on 64-bit architectures. LibGMP之所以这样做是因为它在64位体系结构上所做的操作要快得多。 Multiplying large integers can be around 4x as fast on 64-bit as 32-bit. 乘以大整数可以在64位和32位上快4倍左右。
Warning: Your project will not run on other people's computers unless they install GMP first. 警告:除非他们先安装GMP,否则您的项目不会在其他人的计算机上运行。
Warning 2: If you statically link with GMP to simplify installation, you are required to open-source your application. 警告2:如果您静态链接GMP以简化安装,则需要开源应用程序。 Don't statically link unless you are okay with that. 除非你对此感到满意,否则不要静态链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.