Having Trouble with BigInteger Library

Pages: 12
I downloaded Matt McCutchens's BigInteger library but Im having some trouble using it. I tried the same exact code he has in his sample but I get an error:

1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include "BigIntegerLibrary.hh"


int main ()
{

    BigInteger a = 65536;
    std::cout << (a * a * a * a * a * a * a * a);
}



This gives the following errors:
obj\Debug\main.o||In function `main':|
C:\Users\Imam_Arslan\Desktop\Tutoring\main.cpp|20|undefined reference to `BigInteger::BigInteger(int)'|
C:\Users\Imam_Arslan\Desktop\Tutoring\main.cpp|21|undefined reference to `operator<<(std::ostream&, BigInteger const&)'|
obj\Debug\main.o||In function `ZNK10BigIntegermlERKS_':|
C:\Users\Imam_Arslan\Desktop\Tutoring\..\bigint-2009.05.03\BigInteger.hh|156|undefined reference to `BigInteger::multiply(BigInteger const&, BigInteger const&)'|
||=== Build finished: 3 errors, 5 warnings (0 minutes, 1 seconds) ===|



No idea why this wouldn't work. I tried including all the other headers as well, but still end up with errors.

And before you tell me I should use GMP, I know I probably should. But Im curious as to what the problem is here and want this to work. Thanks.
Last edited on
Nope, even cout << a doesn't work...
Nope, still doesn't working. Even when removing the cout, I still get that first error in the OP.
closed account (48T7M4Gy)
.
Last edited on
Consider using boost::multiprecision
Supports move semantics, and uses expression templates to elide the generation of temporaries.
http://www.boost.org/doc/libs/1_61_0/libs/multiprecision/doc/html/boost_multiprecision/intro.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/gmp.hpp>

int main ()
{
    
    {
        // benign: boost licenced
        using big_int = boost::multiprecision::cpp_int ;
        const big_int a = 1234567890987654;
        std::cout << (a * a * a * a * a * a * a * a) << '\n' ;
    }
    
    {
        // faster and viral: use GMP as the underlying implementation (link with libgmp)
        using big_int = boost::multiprecision::mpz_int ; 
        const big_int a { "123456789098765432101234" } ;
        std::cout << (a * a * a * a * a * a * a * a) << '\n' ;
    }
    
}

http://coliru.stacked-crooked.com/a/f3484c7990605f3c
closed account (48T7M4Gy)
.
Last edited on
closed account (48T7M4Gy)
.
Last edited on
Okay, so Im downloading boost now, from here: https://sourceforge.net/projects/boost/files/boost/1.61.0/

Is that fine?

Once I have it installed, I'll try what JLBorges did. This is my first time using Boost so I'll probably have some questions.
closed account (48T7M4Gy)
.
Last edited on
Wow, this actually works pretty well. I raised a number even bigger than JLBorges to the 10,000th power and it actually printed it out. How far can I take this? How big of a number can it calculate and print out?

Also, what is the maximum value that 'a' can hold? Because I noticed that when I assigned a 20-digit number to 'a' I got a compiler error.
> I raised a number even bigger than JLBorges to the 10,000th power and it actually printed it out.
Probably the std::boost library makes extensive uses of STL containers such as std::vector.

> How big of a number can it calculate and print out?
> Also, what is the maximum value that 'a' can hold?
(Error : Unlimited)

> I noticed that when I assigned a 20-digit number to 'a' I got a compiler error.
The complier can only support raw numbers with certain value ranges. If you use c-string, the problem is eliminated and you would probably achieve the unlimited effect :

a = "6494315784660015461184994613342480077764431945554213346799401546643122245788849461333288810424311613840488810004243499944611333124000481216644311222458466119944015466431222457888494613332888104243116138404888100042434999446113331240004812166443112224584661199440154664312224578884946133328881042431161384048881000424349994461133312400048121664431122245846611994661333422215548880445554221333346644499998000505050505646463131997979776464646464015466431222457888494613332888104243116138404888100042434999446113331240004812166443112224584661199446431318102643194561314049164315810479413646640194464305994461341652610165661961";

See :
https://msdn.microsoft.com/en-us/library/s3f49ktz.aspx
I downloaded version 1.61.0 of boost but im getting "fatal error: no such file or directory". This is even after I went under "build options" and added the file as a relative path.

Im confused and frustrated as I have no idea why its not working (it was working with the previous version just fine). Any help?
Last edited on
closed account (E0p9LyTq)
Why are you downloading a different version of boost just to get these errors?

1.61.0 is the current version.

@Arslan7041,
There are two Get Started guides, one for Windows and another for Unix variants:
http://www.boost.org/doc/libs/1_61_0/more/getting_started/index.html

The instructions for Windows are a bit outdated if you are using Visual Studio 2015, the guide uses VS 2005 and .NET 2003. Not too hard to make the changes, though.

Getting Boost to work for me took several hours, with lots of build errors. I reread the "Getting Started" instructions each try and changed the build settings until it worked.
Last edited on
Most of boosts functionality is in header files only. Only a few actually require linking to anything. Though yes getting boost to work can be a complicated process if you are not familiar with linking and setting include directories.

If you are using Visual Studio there is an easier route that automate all the setup for boost. All you need to do is use the Nuget package for boost.

https://www.nuget.org/packages/boost

To use the package console to install boost for your Visual Studio project follow these steps.

1. - Open your solution in Visual Studio
2. - Go to Tools->Nuget Package Manager->Package Manager Console in the menu bar.
3. - In the console at the bottom copy and paste Install-Package boost
4. - Hit enter and let it run. You are now good to use boost in that project.

Nuget highly simplifies the linking process of third party libraries for Visual Studio so it can be helpful if you either don't want to mess around with setting up libraries or you are still learning how to link libraries.

Though I will say Nuget isn't a replacement for learning how to link against libraries like Boost. Knowing how to link against libraries is something that is a must for every programmer.
Last edited on
closed account (E0p9LyTq)
@Zereo,

I tried Nuget and had more problems than simply following the instructions at Boost's Getting Started pages.

It sure was a good learning experience.
What problems are you having exactly? Hard to help without more information.
closed account (E0p9LyTq)
@Zereo, currently I am not having any problems with Boost. I was simply mentioning my experience when I first began to use the Boost libraries.
Im using CodeBlocks. The error im getting is:

fatal error: boost/multiprecision/cpp_int.hpp: no such file or directory


I read the guidelines for windows but honestly they did not help. The guidelines are for visual studios which is not what im using. If there are simplified instructions someone can give me that would be great.

Keep in mind that I've already set the boost folder as a relative path by going under "build options". This still did not work.
Last edited on
At this point I feel as If I've exhausted all my resources, and still I did not get it to work.

I think I will just re-install the older version and see what happens with that.
closed account (E0p9LyTq)
@Arslan7041,

You might want to join the Boost Users mailing list, it is oriented to the casual user of Boost and people having problems getting started using Boost.

http://www.boost.org/community/groups.html#users
Pages: 12