简体   繁体   English

是否可以在 C++ 代码中使用库 GMP 而无需安装它?

[英]Is it possible to use the library GMP in C++ code without installing it?

I'm trying to build a portable project that uses a library and that library uses GMP.我正在尝试构建一个使用库且该库使用 GMP 的可移植项目。 I am wondering if it is possible to use a statement like #include "gmpxx.h" with GMP's code in my project's directory.我想知道是否可以在我的项目目录中使用带有 GMP 代码的 #include "gmpxx.h" 之类的语句。

Yes, as Marc Glisse pointed out, if performance is not so important to you, and you are not calculating with very very large numbers, GMP has a small footprint library-within-the-library version called "mini-gmp" which is almost fully compatible with the GMP interface, comprising calculations on natural numbers ( mpn ), integers ( mpz ), and rationals ( mpq ), see here and here for details.是的,正如 Marc Glisse 指出的那样,如果性能对您来说不是那么重要,并且您没有使用非常大的数字进行计算,GMP 有一个占用空间很小的库内版本,称为“mini-gmp”,几乎与 GMP 接口完全兼容,包括对自然数 ( mpn )、整数 ( mpz ) 和有理数 ( mpq ) 的计算,请参阅此处此处了解详细信息。 Almost all issues with mini-gmp have been fixed .几乎所有与 mini-gmp 相关的问题都已修复

You don't ever install mini-gmp, basically you #include "mini-gmp.c" in your code (and #include "mini-mpq.c" if rational numbers required) and you are ready to go.你永远不要安装微型GMP,基本上你#include "mini-gmp.c"在你的代码( #include "mini-mpq.c"如果需要的话有理数),你准备好去。 Or just compile mini-gmp.c as a separate compilation unit and use the declarations in mini-gmp.h .或者只是将mini-gmp.c编译为单独的编译单元并使用mini-gmp.h的声明。 Also, there's a test suite in the directory you may run with make .此外,您可以使用make运行的目录中有一个测试套件。

Note, though, that if your application is mission-critical you may run into problems because all microarchitecture optimizations and code for arithmetic on asymptotically large numbers are not included in mini-gmp.但是请注意,如果您的应用程序是关键任务,您可能会遇到问题,因为 mini-gmp 中不包含所有微体系结构优化和渐近大数算术代码。

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

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