How to set up Visual Studio 2015 Project with MPFR
This guide will help you get up and running with a VS project using MPFR and MPIR (a Windows port of GMP) using some prebuilt binaries. (Here is a link to a VS project and the downloaded binaries I mention: https://www.dropbox.com/s/p08cw59bic4f02v/MPFR-VSProj.zip?dl=1)
Getting the Precompiled Binaries
Visual Studio project settings:
- Change the Configuration to "Release, x86"
This is necessary to get going for now since we are missing the debug
dlls in the 2010 Redistributable (should have been installed as part of
VS install)
- Create a 'libs' and 'include' folder in the $(SolutionDir) (top level dir where
the solution is kept.
- Copy over the right files into these folders:
- mpfr_mpir_x86_x64_msvc2010:
- From 'Win32 > Release' folders for mpfr and mpir
- Copy *.dll, *.exp, *.lib and *.pdb to $(SolutionDir)/lib directory
- All header files to the $(SolutionDir)/include directory
- mpfrc++-3.6.2
- Add mpreal.h to your project (or in $(SolutionDir)/include if you prefer)
- The header is all you need for the c++ wrapper
- Tell VS where to look for the newly created 'include' and 'lib' directories
Configuration Properties > VC++ Directories
- Include Directories: add path to your include directory
- Library Directories: add path to your lib directory
- Link the lib's *.lib files
Configuration Properties > Linker > Input > Additional Dependencies
- Add the following to this list: mpfr.lib; mpir.lib;
- Using compiler options, change the runtime library:
Configuration Properties > C/C++ > Code Generation > Runtime Library
- select "Multi Threaded DLL (/MD)"
- Set the compiler arguments for building:
Configuration Properties > Debugging > Command Arguments
- Force the DLLs to get copied to the output directory
Configuration Properties > Build Events > Post-Build Event
- Command Line: 'XCOPY "$(SolutionDir)lib*.dll" "$(TargetDir)" /D /K /Y'
- Description: 'Copy DLLs to Target Directory'
- Use in Build: YES
Tell VS to clean up the DLLs when it cleans up an output folder:
Configuration Properties -> General -> Extensions to Delete on Clean
To Test your project, copy over the main() from "example/example.cpp" from
the mpfrc++-3.6.2 folder
- Make sure to add an include your mpreal.h file after your stdafx.h include
Helpful SO Articles: