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

北城余情 提交于 2019-11-26 23:26:03

问题


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.vcproj for VC++.Net) to build GMP" I get many building errors. You can download it here: http://www.f2h.co.il/msbz68nzzip. There are many errors like "fatal error C1083: Cannot open include file: 'fib_table.h': No such file or directory".

Is there an other tutorial? What should I do?

I'm using Visual Studio 2010 on Windows 7.


回答1:


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++




回答2:


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://dl.dropboxusercontent.com/u/90643534/MPFR-VSProj.zip)

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?


来源:https://stackoverflow.com/questions/19688442/how-to-install-mpfr-and-gmp-for-c-on-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!