0

I'm trying the simple example of boost multiprecision in c++ without installing it on my computer (using it header only).

//func.cpp
#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>

int main()
{
   using namespace boost::multiprecision;

   int128_t v = 1;

   // Do some fixed precision arithmetic:
   for(unsigned i = 1; i <= 20; ++i)
      v *= i;

   std::cout << v << std::endl; // prints 20!

   // Repeat at arbitrary precision:
   cpp_int u = 1;
   for(unsigned i = 1; i <= 100; ++i)
      u *= i;

   std::cout << u << std::endl; // prints 100!

   return 0;
}

I'm running ubuntu and I've copied the boost folder into the main folder I'm trying to run func.cpp in. I then run:

g++ -I/boost/ -o func func.cpp

I get the error

In file included from func.cpp:28:
boost/multiprecision/cpp_int.hpp:11:10: fatal error: boost/cstdint.hpp: No such file or directory
   11 | #include <boost/cstdint.hpp>
      |          ^~~~~~~~~~~~~~~~~~~
compilation terminated.

It appears that cpp_int.hpp is #include-ing a header that is located one directory above it (inside the boost folder I copied in, I've checked, it's there). I'm probably missing something basic since I get the same type of errors when trying to use other packages.

  • 5
    Do you really have a `/boost` subdirectory in your root directory, and that's where you installed boost? And why exactly are you installing Boost yourself, manually, in Ubuntu, when Ubuntu already has a perfectly configured boost package, ready to install, without any further effort on your part? – Sam Varshavchik Sep 17 '20 at 18:52
  • substitute `#include "boost/multiprecision/cpp_int.hpp"` (instead of `<>`), and make sure you set the appropriate compiler "include" option (e.g. `-I`). ALSO: I suspect you'll probably want something like `-I /my/path/boost`. in which case you'd probably want `#include "multiprecision/cpp_int.hpp"` (without the top-level "boost/"). Look [here](https://stackoverflow.com/a/5191032/421195) for more details. – paulsm4 Sep 17 '20 at 18:52
  • It's usually installed into /usr/include/boost and -I/usr/include is by default. So that's why it needs and if you add include directory to boost ( /boost/ sounds weird, if you don't want to install it...) then it should be accessible by include – KIIV Sep 17 '20 at 18:55
  • 1
    How (and *where*) did you install Boost? – Some programmer dude Sep 17 '20 at 18:57
  • So it does seem that it is successfully reaching my cpp_int.hpp file, since that is the file causing the problem. It looks like it can't find . So maybe this is the reason (thanks for the link paulsm4), it's looking for an installed boost in /usr/include? Is there a way to fix this without going into every file of my downloaded package and replacing #include with "./appropriatepath/whatever". I'd prefer not to install boost if I don't need to. – Carl Kohrs Sep 17 '20 at 19:14
  • You need to add the folder that contains the boost folder to your include directories for `#include ` to work. You don't want to alter this path. – drescherjm Sep 17 '20 at 19:21
  • Thank you dreschrjm (and others). My error was that I had copied the boost folder inside the boost_1_74_0 folder into my root (thinking that I don't need the install files, documentation etc). This created the problem since it was looking for cstdint.hpp inside "-I included folder"/boost. Sorted now, thanks very much. – Carl Kohrs Sep 17 '20 at 19:31

0 Answers0