1

I'm trying to build a portable project that uses a library and that library uses 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.

robathan
  • 11
  • 1
  • 1
    Lookup statically linking as opposed to dynamically linking. Not standard on unices though – Jeffrey Jul 07 '21 at 21:46
  • I would expect putting the code in your project directory and attempting to build will not work. – drescherjm Jul 07 '21 at 21:54
  • 1
    You can install GMP in a sub directory of your user's home directory instead of installing in the system directories. Then you can build your project against that local copy. So you are "installing" it but just in your own directory. – Jerry Jeremiah Jul 07 '21 at 23:35
  • According to this, GMP can be statically linked: https://stackoverflow.com/questions/8057078/error-when-statically-linking-libgmp-on-linux – Jerry Jeremiah Jul 07 '21 at 23:36
  • Also, this might be helpful: https://stackoverflow.com/questions/44780261/how-do-i-create-so-files-with-all-libraries-statically-linked-into-it – Jerry Jeremiah Jul 07 '21 at 23:38
  • Possibly useful, if you are going to install it locally: https://gmplib.org/manual/Build-Options – Jerry Jeremiah Jul 07 '21 at 23:41
  • 1
    Depending on what functions are used, mini-gmp might be an option (https://gmplib.org/repo/gmp/file/tip/mini-gmp). – Marc Glisse Jul 08 '21 at 05:25

1 Answers1

0

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. Almost all issues with mini-gmp have been fixed.

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. Or just compile mini-gmp.c as a separate compilation unit and use the declarations in mini-gmp.h. Also, there's a test suite in the directory you may run with 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.

Arc
  • 412
  • 2
  • 16