Note: I did everything in x64
& release
. I did not do debug
nor x86.
Part 1: - The first section involves acquiring all of the tools needed to set everything up:
Make sure that you have the newest version of Python installed into Visual Studio. Make a script and test it to make sure Python is working correctly. Having IDLE for Python is also very handy. It will save you from having to load it into VS to do simple repetitive tasks of running the scripts. For developing that's probably where I would stick with Visual Studio's IDE.
If you are on windows you will need vyasm: you can get the latest distributions from here: http://yasm.tortall.net/Download.html. You can download both the Win32 & Win64 zips for Visual Studio 2010, but only the x64 should be needed unless if you are on an x86 only machine. You can then save them into a working directory on your desktop. These alone will not do it. You will need another tool for yasm to work with visual studio 2017 on Windows properly. You will also have to configure a few things. You will also need this clone that you can download as a zip that will help with getting yasm to work with Visual Studio properly. It can be found here: https://github.com/ShiftMediaProject/VSYASM. Save this into the same working directory but do not do anything as of yet. We will come back to this after we have the rest of the tools needed.
Acquire the latest unmodified MPIR distribution 3.0.0 & its documentation from here: http://mpir.org/downloads.html. I used the MPIR source zip and its PDF is very useful while walking through the steps of setting up MPIR. Save these into the same folder as above.
This doesn't exactly pertain to MPIR but they go hand in hand we can go ahead and get MPFR's latest unmodified distribution 4.01 from here: http://www.mpfr.org/mpfr-current/#doc] in which I have yet to do. For this you will also need a dependency wrapper library for C++. You will need MPFRC++ latest unmodified distribution 3.6.2 from here: http://www.holoborodko.com/pavel/mpfr/#download. Again save them to the same directory. Now if you want you can also acquire another similar library that is similar to MPIR & MPFR for doing complex numbers, but that is outside the scope of this setup.
Now that we have everything we need: and that Python is already setup and working, we can begin to set up and configure Yasm.
Part 2 - This next step is to properly integrate vyasm
(yasm) with Visual Studio
We will first do the x86 - 32bit version if you downloaded it and all of the procedures are the same if you don't already have yasm installed. (It has to be the vyasm
) version that is designed to integrate into visual studio and not the general purpose ones.
In the working directory you want to extract the vsyasm-1.3.0-win32.zip
into a folder called yasm
. Once done you will want to place this into C:\Program Files (x86)\
. Once you have them in that directory you can remove the temp folder that you extracted them from in your working directory, but keep the zips for future uses.
In the same working directory, you want to extract the vsysam-1.3.0.win64.zip
into a folder called yasm
. The same thing except it will go into the win 64 director: C:\Program Files\
. Once you are done with this you will want to remove the temp folder in the working directory.
You will want to go into your system settings and you will add 2 environment variables. If you don't know how to do that I will guide you: Click Start
, Right Click Computer
, Select Properties
. On the left-hand side Click Advanced System Properties
. (This may be different if you are on Windows 8 or 10). Once you have the System Properties Dialog Box
up, you will want to select the Advanced Tab
. On this tab towards the bottom Click Environment Variables
. On the bottom half under System Variables
you will want to click New
, The first field (variable name:) you will want to type YASMPATH32
. For the 2nd field (variable value:) you will want to type C:\Program Files (x86)\yasm
. Then select okay to set the variable. You will repeat this for the 64-bit version. Click Add
and for (variable name:) YASMPATH64
and for (variable value:) C:\Programming Files\yasm
and click okay. If you noticed closely I did not use an ending \
or /
and I did this on purpose. You will see why later on when we set up yasm to work in Visual Studio. Click Okay
to close Environment Variables
, Click Okay
again to close System Properties
and close Control Panel
.
Back to the working directory, you will want to extract VSYASM-master.zip
to a folder. You will want to follow the instructions from the readme or you can read them from the Github page from the download above. I basically just ran the bat
file from an elevated command prompt. I applied the batch file but I'm also using that in conjunction with the system environment variables which will be needed later.
Open Visual Studio and create an empty win32 console application; no precompiled headers. You will want to create two source files main.cpp and an arbitrary *.asm file. Follow this brief tutorial to make sure that Yasm
and Visual Studio 2017 are working together: https://www.cs.uaf.edu/2017/fall/cs301/reference/nasm_vs/. If both the CPP & ASM file compile on their own and you are able to build without error. Then things are looking good. If you can not get a clean build, then keep checking over the previous steps. Once you have a clean build let's verify that Yasm is working correctly. You will need to run this with & without debugging in debug mode x64 version. The only difference from the program on the website is that I did this in the CPP file:
#include <iostream>
extern "c" int foo( void ); // written in asm
int main() {
int x = foo();
std::cout << x << '\n';
std::cin.get(); // pause window from closing
return 0;
}
If you get the value 7. We are good to go with Yasm
.
Part 3: - Working with Visual Studio & Python to build the needed libraries
Now its time to get our feet wet and start working with Visual Studio
, Python
and MPIR
. Before we do dive in; close everything except for the working folder that everything was downloaded to. This is just to ensure there aren't any discrepancies when going through this long process. You can choose any folder you like on your system, but you will need to remember where that folder is. It is best to put it close to the root of a drive with all other 3rd party dependency libraries that you link against. This way, it is easy to make environment variables for each of your libraries and to easily set their include and linking paths. This will vary depending on the use of static or dynamic libraries, but that is outside of the scope of this setup. We are only interested in building the libraries and running the tests to make sure that they work properly. Having the accompanying PDF for MPIR
is good to have open as well as this website: http://panu28.blogspot.com/2017/06/multi-precision-mpir-mpfr-libraries.htm. Between the two I was able to get them working. We don't have to worry about step 1 from the website as that is already taken care of. Before we try to run the python script mpir_config.py
we need to go to our working folder.
You want to extract it where it is for it should already be in a folder. After it is extracted remove all the symbols and numbers out of the name so that the folder should look like this: mpir
. Move this folder into the folder that you want your libraries to live. It's not needed but we can do the same exact thing for mpfr
by extract it and removing the extra characters from its name. It should look like mpfr
. On my system I have this kind of folder structure: C:\Programming Libraries\mpirfr-vs2017\
and this is were the folders mpir
and mpfr
live. For the last one mpfrc++-3.6.2.zip
We need to extract this into a folder. The folder can be mpfrc++-3.6.2
. And again we can place this into the same folder that we moved the other one into. If you also have the complex
library you can place that there to. You don't have to use the same name for the folder as I did but as long as you know what folder they are in all, you should be good.
Open the mpir
folder in your library kit (this should be the unmodified distribution). Go into build.vc
folder. If you have Python installed with IDLE then right click on mpir_config.py
and select edit with IDLE 3.6 - 64bit
This will open the python. Now go to Run
& Run Module
or F5
. Here you want to select all the types that you want to build, but for now pick one for your primary target! And press enter for the script to accept the parameter. Leave these windows OPEN!
Go back to the library directory and navigate back one level and then go into build.vc15
. In here open mpir.sln
This will load up Visual Studio with all the projects. DO NOT TRY TO BUILD YET!
Make sure you are in Release & x64 if you are on a 64bit machine. Look for the project that you selected from the python script for the one you wanted. Since I have an Intel Core 2 Quad Core Extreme I ended up building these libraries: dll_mpir_core2_penryn
and for the static I had to do 2 for c++ support lib_mpir_core2_penryn
& lib_mpir_cxx
. Now Do not try to build yet. We need to check some settings but once you do one the rest should be vary similar. You want to open the Project's Properties Page
and under Custom Build Step
add this to the Command Line
field: $YASMPATH64\vyasm.exe
for each of the projects that require asm files to be built.
Now we are ready to try and build. Do not try to build from the menu up top, but rather select the project from Solution Explorer
and Right Click
- Project Only
- Build Only
. If this first succeeds you will see asm files being compiled and you should get no linking errors . If not check your settings.
If it does pass, You can try doing another library from the ones you chosen if you happened to selected multiple projects from the python script. If the 2nd library does happen to fail don't worry. Just close out visual studio and both python windows. Go back into the library directory and go back one level, and look to see if a new dll or lib folder is present depending on which type of library you built. If it is present go into it and check to see if the library is there (dll or lib). You will want to look in the 64 release. If it is present, then yasm is working properly. If it is not or it failed; keep checking the settings. Make sure your environment variables are correct (as the should be from the test asm program above). Some times they failed on me too; but once I got the paths right and everything else: when I built the program I did not do it from the main interface.
After all of the wanted libraries are built we move on the phase 2 of this part. You can now close out the Python IDLE Windows and Visual Studio.
8 . Next is to build the test libraries: from the root mpir
directory go into build.vc15
open mpir-tests.sln
In this solution, you want to right click on add-test-lib
and you want to only build this but make sure it is in Release
& 64bit
After this is built successfully, then you can right click on the solution and select build solution. This will build about 200 projects. They should all pass. We do not need to change any settings here. After they are built we can close visual studio.
Go back to the library directory. The same path that had the solution we just opened. Now go into mpir-tests
folder. Scroll to the bottom and right click on run-tests.py
- Edit with IDLE - 64bit
. Press F5 and wait a couple of minutes.... If everything went right you will see success going down and hopefully now fails. On my system I had one obscure message: Test skipped, replacing localeconv/nl_langinfo doesn't work
however at the end of the python module (script) I got the message: 203 tests: 203 ran correctly
.
You can close exit and close out the python windows and visual studio.
We are almost there! :) I can smell the roses or coffee!
Go back one directory in the library and open mpir-tune.sln
. Make sure you have Release
& x64
set for all the projects. First you want to build add-test-lib
only from right clicking on it in Solution Explorer. After that builds go to the bottom project tune
and open its Property Page
then under Custom Build Step
- General
- Command Line
add this: $YASMPATH64\vyasm.exe
. Its the only project that relies on asm
. After that is set then you can build the rest of the projects starting from the 2nd from the top down the list. After all 5 of these are built you can close Visual Studio. Now back in the library directory you will want to open the run-speed.py
from IDLE - 64
and press F5 or you can just double click it and run it through the command prompt. Finally you can go into the root mpir
directory and check in the dll
and lib
folders for all of your library files.
I hope this helps anyone in need, and please take into consideration that this walk through is targeted to towards Windows 7 - 64bit Home Premium on an Intel Core 2 Quad Extreme, using Visual Studio 2017CE v. 15.6.6. However this can be useful as a general step by step guild into building the needed libraries. I can not guarantee that they are 100% bug free but they all did build successfully. I did notice or see a handful of basic warnings (conversion - might be loss of data (truncation)), unsafe use of this or that, this has been marked as deprecated etc. But I was able to build out everything without compiler and without linker errors. This Q/A was inspired by a comment section on github about a specific linker error that I had encountered as the original OP had come across. You can find that post hereGithub/wbhart/mpir/issues/229. If you have any comments or questions please feel free to let me know what you think!
--Enjoy--