roxrook
roxrook

Reputation: 13853

How to build mpir-2.4.0 with Visual Studio 2010?

I followed the instruction from Rick Regan http://www.exploringbinary.com/how-to-install-and-run-gmp-on-windows-using-mpir/. Unfortunately, for some reasons, the static library only works with C. For C++, the compiler always complains about linker problems. There are several differences between the current version that I use (2.4.0) with the version of Rick Regan. On the other hand, I also followed the readme.txt inside build.vc10 folder, but I still couldn't figure out why it was broken. I'm running Windows 7 x64 and using Visual Studio 2010 - Ultimate. To be more specific:

After building those solutions, it generate a folder named Win32, and inside this folder there is another folder named Release in which there are four other library files:

enter image description here

Besides, the lib folder inside build.vc10 also generates two other folders:

Next, I copied all the library files from build.vc10\lib to my C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include as well as mpir.h and mpirxx.h to my C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include.
After finish all these steps, I create a Win32 Console Application project, and add two Additional Options under Project Properties\Linker\Command Line\. They are:

Then I built some examples with C and it worked as expected. However, when I tried this particular example:

#include <iostream>
using namespace std;

#pragma warning(disable: 4800)
#include <mpirxx.h>
#pragma warning(default: 4800)

int main (int argc, char *argv[])
{
    mpz_class aBigPO2;

    aBigPO2 = 1073741824; //2^30
    aBigPO2*=aBigPO2; //2^60
    aBigPO2*=aBigPO2; //2^120
    aBigPO2*=aBigPO2; //2^240
    aBigPO2*=aBigPO2; //2^480
    aBigPO2*=aBigPO2; //2^960
    aBigPO2*=aBigPO2; //2^1920

    cout << aBigPO2 << endl;
}

It failed with many errors:

1>main.obj : error LNK2001: unresolved external symbol ___gmpz_set_si
1>main.obj : error LNK2001: unresolved external symbol ___gmpz_init
1>main.obj : error LNK2001: unresolved external symbol ___gmpz_mul
1>main.obj : error LNK2001: unresolved external symbol ___gmpz_clear

And I have no idea why this happened. I even tried to copy other alternatives from Win32 folder but it still produced the same errors. But I'm not sure how these files are different though. I'm running Windows 7 x64 but I don't think my Visual Studio is x64. I wonder mixing 32bit and 64bit could cause this issue. Any idea? Thank you.

Upvotes: 3

Views: 6622

Answers (2)

crit1que
crit1que

Reputation: 11

I'm guessing you built the x64 libraries? I did, and then encountered similar issues to what you're stuck with. Make sure to configure your MSVC project correctly for use with x64 libraries ... this link should help: How to compile a 64-bit application using Visual C++ 2010 Express?

Upvotes: 1

john
john

Reputation: 88027

Although you have built the release version of MPIR, you are using it in a debug version of your own project. Build the debug version of MPIR or switch to the release version of your project.

Upvotes: 1

Related Questions