BigInt library

Pages: 12
Hi, I need a library to deal with very large numbers, I downloaded the BigInteger library (https://mattmccutchen.net/bigint/) and tried running the sample.cc file in my Coderunner app but I get the error message below. Anyone either used this library successfully before, or can help me with what the error message means?

NB. I tried gmp and can't seem to install that properly. This one seems simpler, I would rather get this working if I can.



Undefined symbols for architecture x86_64:
"BigInteger::BigInteger(int)", referenced from:
_main in ccYX7kPc.o
"BigInteger::operator=(BigInteger const&)", referenced from:
_main in ccYX7kPc.o
BigInteger::operator%(BigInteger const&) constin ccYX7kPc.o
BigInteger::operator/(BigInteger const&) constin ccYX7kPc.o
"BigInteger::toInt() const", referenced from:
_main in ccYX7kPc.o
"stringToBigInteger(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
_main in ccYX7kPc.o
"bigIntegerToString(BigInteger const&)", referenced from:
_main in ccYX7kPc.o
"operator<<(std::basic_ostream<char, std::char_traits<char> >&, BigInteger const&)", referenced from:
_main in ccYX7kPc.o
"BigUnsigned::BigUnsigned(unsigned int)", referenced from:
_main in ccYX7kPc.o
"BigUnsigned::BigUnsigned(int)", referenced from:
_main in ccYX7kPc.o
"operator<<(std::basic_ostream<char, std::char_traits<char> >&, BigUnsigned const&)", referenced from:
_main in ccYX7kPc.o
"modexp(BigInteger const&, BigUnsigned const&, BigUnsigned const&)", referenced from:
_main in ccYX7kPc.o
"modinv(BigInteger const&, BigUnsigned const&)", referenced from:
_main in ccYX7kPc.o
"gcd(BigUnsigned, BigUnsigned)", referenced from:
_main in ccYX7kPc.o
"BigUnsigned::multiply(BigUnsigned const&, BigUnsigned const&)", referenced from:
BigUnsigned::operator*=(BigUnsigned const&)in ccYX7kPc.o
"BigUnsigned::bitShiftRight(BigUnsigned const&, int)", referenced from:
BigUnsigned::operator>>(int) constin ccYX7kPc.o
"BigUnsigned::bitShiftLeft(BigUnsigned const&, int)", referenced from:
BigUnsigned::operator<<(int) constin ccYX7kPc.o
"BigUnsigned::bitXor(BigUnsigned const&, BigUnsigned const&)", referenced from:
BigUnsigned::operator^(BigUnsigned const&) constin ccYX7kPc.o
"BigUnsigned::bitOr(BigUnsigned const&, BigUnsigned const&)", referenced from:
BigUnsigned::operator|(BigUnsigned const&) constin ccYX7kPc.o
"BigUnsigned::bitAnd(BigUnsigned const&, BigUnsigned const&)", referenced from:
BigUnsigned::operator&(BigUnsigned const&) constin ccYX7kPc.o
"BigInteger::divideWithRemainder(BigInteger const&, BigInteger&)", referenced from:
BigInteger::operator%(BigInteger const&) constin ccYX7kPc.o
BigInteger::operator/(BigInteger const&) constin ccYX7kPc.o
"BigInteger::multiply(BigInteger const&, BigInteger const&)", referenced from:
BigInteger::operator*(BigInteger const&) constin ccYX7kPc.o
"BigInteger::subtract(BigInteger const&, BigInteger const&)", referenced from:
BigInteger::operator-(BigInteger const&) constin ccYX7kPc.o
"BigInteger::add(BigInteger const&, BigInteger const&)", referenced from:
BigInteger::operator+(BigInteger const&) constin ccYX7kPc.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

> Undefined symbols for architecture x86_64:
> "BigInteger::BigInteger(int)"

This library is not a 'header-only' library; you need to compile and link with other files containing the implementations of BigInteger, BigUnsigned etc.

Look at the set of files that you downloaded; look for files with names like BigInteger.cc, BigUnsigned.cc and add them to the project.


If you want an easy to use 'header-only' library, consider boost::multiprecision::cpp_int.
See this thread: http://www.cplusplus.com/forum/beginner/114165/
Thanks for your reply, to be honest I'm completely lost with this stuff. I'm pretty new to programming and this is the first time I've used an external header library. In fact, I only first tried out writing and using my own very simple headers about a week ago. I'm using an app called Coderunner and you can do a 'customized run' where you can enter into fields called Arguments, Compilation flags or Program input. Should I include the paths for .cc files in one of thee fields? The sample.cc program provided does not take arguments so I don't think I add files to link in that field.

I have tried using Xcode too and can run my simple command line programs but apart from that I find it extremely confusing and difficult to use.

I'm also a beginner using the terminal.

Any suggestions for something I can read to help me understand all this?

I'll try downloading the Boost library as you suggested and report back. A quick glance at the thread you linked makes me think it isn't that simple to install...
Last edited on
The Boost library does not need to be installed or compiled, just place it in the folder with your other header files and then just #include it.
I'm such a noob I don't even know where the header files are on my Mac :(

Do I place the entire boost_1_54_0 folder in there? At the moment it is on my Desktop
Do you know how to compile a program from the command line (terminal)?
OK I think I found the header files

Macintosh HD > Developer > usr > lib > c++ > v1 >

The v1 folder contains headers I recognize such as 'string', 'iostream', 'iomanip' and 'vector'.

So I literally just shove the boost folder in there?
Extract the boost files into a separate folder of its own. (Avoid writing anything into the directories containing standard header files).
Do you know how to compile a program from the command line (terminal)?


Kind of. I can run programs saved on my desktop by doing

cd desktop

then

make program name

then an exe file appears on desktop, which I can drag into the terminal window to run the program...
Extract the boost files into a separate folder of its own. (Avoid writing anything into the directories containing standard header files).


I extracted the boost files, then there was a folder called boost_1_54_0 in my downloads folder, which I moved from downloads to desktop. Inside this folder there is another folder called 'boost'
Last edited on
Ok. I suppose you are unfamiliar with make files.

In the terminal window, if you type
CC --version followed by enter
what does it print out?
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Fine.

And if you type in
pwd followed by enter
what does that print out?

/Users/plangto
Ok.

1. write this program and save it in /Users/plangto (say, as bignum_test.cc )

1
2
3
4
5
6
7
8
9
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>

int main()
{
    boost::multiprecision::cpp_int i( "1234567890987654321" ) ;

    std::cout << i * 12345 << '\n' ;
}


2. In the terminal, type in
CC -std=c++98 -Wall -I /Users/plangto/Desktop/boost_1_54_0 -o bignum_test bignum_test.cc followed by enter.

3. When the prompt appears, type in ./bignum_test followed by enter.
Still getting errors after step 2, this is not all of it, it's too long to paste everything

Undefined symbols for architecture x86_64:
"std::cout", referenced from:
_main in ccztU60S.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)", referenced from:
_main in ccztU60S.o
"std::terminate()", referenced from:
_main in ccztU60S.o
boost::exception_detail::copy_boost_exception(boost::exception*, boost::exception const*)in ccztU60S.o
boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0u, 0u, (boost::multiprecision::cpp_integer_type)1, (boost::multiprecision::cpp_int_check_type)0, std::allocator<unsigned int> >, (boost::multiprecision::expression_template_option)1>::number<boost::multiprecision::detail::multiply_immediates, boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0u, 0u, (boost::multiprecision::cpp_integer_type)1, (boost::multiprecision::cpp_int_check_type)0, std::allocator<unsigned int> >, (boost::multiprecision::expression_template_option)1>, int, void, void>(boost::multiprecision::detail::expression<boost::multiprecision::detail::multiply_immediates, boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0u, 0u, (boost::multiprecision::cpp_integer_type)1, (boost::multiprecision::cpp_int_check_type)0, std::allocator<unsigned int> >, (boost::multiprecision::expression_template_option)1>, int, void, void> const&, boost::enable_if_c<boost::is_convertible<boost::multiprecision::detail::expression<boost::multiprecision::detail::multiply_immediates, boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0u, 0u, (boost::multiprecision::cpp_integer_type)1, (boost::multiprecision::cpp_int_check_type)0, std::allocator<unsigned int> >, (boost::multiprecision::expression_template_option)1>, int, void, void>::result_type, boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0u, 0u, (boost::multiprecision::cpp_integer_type)1, (boost::multiprecision::cpp_int_check_type)0, std::allocator<unsigned int> >, (boost::multiprecision::expression_template_option)1> >::value, void>::type*)in ccztU60S.o
boost::enable_if<boost::is_arithmetic<unsigned int>, int>::type boost::multiprecision::backends::cpp_int_backend<0u, 0u, (boost::multiprecision::cpp_integer_type)1, (boost::multiprecision::cpp_int_check_type)0, std::allocator<unsigned int> >::compare<unsigned int>(unsigned int) constin ccztU60S.o
Ok. In step 2, change CC to g++. That is:

g++ -std=c++98 -Wall -I /Users/plangto/Desktop/boost_1_54_0 -o bignum_test bignum_test.cc

What happens now?


YES! That works now. It printed the long number :)
Any idea how I can get this to work with the coderunner app?

I do want to learn how to use the terminal properly, and I will, but it would be nice to be able to use this library in the app.
> Any idea how I can get this to work with the coderunner app?

I've never used coderunner; so I'm at a loss. Hopefully, another forum member who is familiar with it would help you out.


> I do want to learn how to use the terminal properly, and I will

When you decide to do that, you might find this tutorial helpful:
http://www.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html
(There are many more on the web; search for them).


> YES! That works now. It printed the long number :)

For C++ programs, we need g++ which is the C++ compiler; that is why it works now.
Earlier it gave errors because we were trying to compile with gcc which is used for compiling C programs.

Pages: 12