How to install MPFR and GMP for C++ on visual studio

后端 未结 3 1582
半阙折子戏
半阙折子戏 2020-12-06 14:35

As I understand, I should first install GMP. The only tutorial I found for this purpose is http://cs.nyu.edu/exact/core/gmp/ and when I reach step 3: \"Open gmp.dsw (gmp.vcp

相关标签:
3条回答
  • 2020-12-06 15:17

    I met similar problem and had just resolved it by download precompiled MPIR and MPFR libraries instead of GMP which needs mingw or similar on Windows.

    Here is the link of my solution: How to install MPFR with Visual studio 2008 /2010

    Hope this help

    Now a perfect solution by @casevh can be found here: Build mpir/mpfr/mpc via VC++

    0 讨论(0)
  • 2020-12-06 15:23

    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

    • Get the pre-compiled files from: http://www.holoborodko.com/pavel/mpfr/#projects

      • mpfr_mpir_x86_x64_msvc2010 (precompiled mpfr mpir with MSVC 2010

        Since it was compiled with MSVC 2010, it needs Microsoft Visual C++ 2010 * Redistributable. If we try to run the program in Debug mode, we won't be able to. we'll get this error: "The program cant't start becaue MSVCP100.dll is missin from your computer". Essentially, MSVCP100.dll is part of the Visual Studio 2010 install but not in the Redistributable, which only contains the dlls needed for release versions of builds

        • NOTE: visual studio still allows one to debug in the Release configuration so debugging isn't a big issue at this stage when you are just trying to get up and running
      • mpfrc++-3.6.2 (c++ wrapper by Holoborodko)

        NOTE: these binaries are a few years old but they are tested and "relatively bug-free"

    Visual Studio project settings:

    1. 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)

    2. Create a 'libs' and 'include' folder in the $(SolutionDir) (top level dir where the solution is kept.
    3. 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
    4. 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
    5. Link the lib's *.lib files

      Configuration Properties > Linker > Input > Additional Dependencies

      • Add the following to this list: mpfr.lib; mpir.lib;
    6. Using compiler options, change the runtime library:

      Configuration Properties > C/C++ > Code Generation > Runtime Library

      • select "Multi Threaded DLL (/MD)"
    7. Set the compiler arguments for building:

      Configuration Properties > Debugging > Command Arguments

      • append: "-lmpfr -lgmp"
    8. 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
    9. Tell VS to clean up the DLLs when it cleans up an output folder:

      Configuration Properties -> General -> Extensions to Delete on Clean

      • add: '*.dll'
    10. 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:

    • How to include libraries in Visual Studio 2012?
    • How do I use a third-party DLL file in Visual Studio C++?
    • Should I compile with /MD or /MT?
    0 讨论(0)
  • 2020-12-06 15:23

    using VCPKG package management system should solve your pain. Most of my use of GNU libs etc under windows is solved in this way.

    0 讨论(0)
提交回复
热议问题