Reputation: 307
First I tried using GMP because boost documentation says it is faster but the gmp.h file was missing from boost library so I had to install GMP library and copy the gmp.h. After doing so I was getting external symbol Error when using mpz_int. So I decided to try cpp_int, copied the example from boost documentation and it worked. this is what I tried:
#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;
}
So then I created a factorial function in a Math class but now every time i use a variable from cpp_int library I receive that error: error LNK2019: unresolved external symbol __CrtDbgReportW referenced in function "void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)" (?_Debug_message@std@@YAXPB_W0I@Z)
Now every time I try to assign a new value to cpp_int variable I get that error, the weird thing is that the example worked and now the same example doesn't work for this project, but if I create a new project and use the same boost lib it works again.
Upvotes: 0
Views: 538
Reputation: 4511
It's likely that one of the library you are using (probably the cpp_int library) wants to link with the Debug version of the Visual Studio runtime library. (Symbol __CrtDbgReportW
is defined in the Debug version of the VS runtime library only.)
Make sure you compile your code for the appropriate target (Debug/Release), the third party libraries you are using are compiled for the same target, and that you link with the corresponding runtime library.
EDIT (after the comments you added earlier) :
Make sure you compile your code for the Static Debug version of the VC runtime library (aka libcpmtd.lib
) :
In Visual Studio, open the Project Properties dialog and, in Configuration Properties
-> C/C++
-> Code Generation
, field Runtime Library
, set to : Multi-threaded Debug (/MTd)
.
Note that any other library you link to your build must have the same setting.
Upvotes: 1