Compiling in Windows
This page explains how to compile code engines using Windows.
Using Visual Studio
Development of NairnMPM and NairnFEA in Windows using Visual Studio. The first step is to install Visual Studio, and a free version is available called "Visual Studio Community 2015" (these notes are based on this version of Visual Studio, but the changes for any future versions should be minor). You can download this IDE from:
https://www.visualstudio.com/vs/community/
Be sure to customize to get VC++ for C++ development. The download is large (15-20 GB depending on options selected) and will take a while.
Installing Xerces
Before you can compile and run the project, however, you will need a compiled version of the xerces.dll library and a copy of the xerces header files. These needed component are installed as follows:
- Got to xerces web site.
- Go to "Download" section and get source distribution zip file, which contains VS projects (as of this writing, it is version 3.1, but newer version should work).
- Extract the contents of the zip file and place the resulting folder in the same folder as nairn-fea-mpm project folder.
- Open the Visual Studio solution in <xerces project at projects\Win32\VC14\xerces-all\xerces-all.sln. Note that this step is "VS14" because it corresponds to version supplied with "Visual Studio Community 2015." The number may change if new "Visual Studios" are made available.
- After loaded, select the XercesLib project.
- Select "Release" target for "x64" platform in the tool bar (these instruction assume you want 64bit builds, which are recommended).
- Build the project. The compiled xerces.dll file will be written to Build\Win64\VC14\Release in the xerces folder.
Using Eclipse IDE
Because the Eclipse IDE can run on multiple platforms, you can use it on Windows for compiling as well. For details, see help on compiling using Eclipse IDE.
Using cygwin
Another alternate approach to compiling in Windows is to install cygwin. This software gives you a Linux/Unix style environment and can work with software by means very similar to use Linux (or Mac in Unix mode). This approach is no longer recommended. First, the code compiled in cygwin seems to run considerably slower that code compiled in Visual Studio on the same machine. Second, when running calculations using the NairnFEAMPMViz app, a bug in java disables the useful feature in that software to abort calculations before they are done. Th e bug is avoid when using code compiled in Visual Studio. The remainder this section should not be used, but it left in place for previous users (or someone that really wants to work in ?cygwin.
Installing and Setting Up cygwin
The nairn-mpm-fea project runs well in Windows by using the cygwin system. You can check out the project, compile the code, run calculations, and visualize the results. This section gives the step-by-step process for the required cygwin setup. This process has been verified in Windows XP, Windows Vista and Windows 7 (although you may need the latest `cygwin 1.7` for Windows 7).
- Download the cygwin setup.exe application and run it (to install cygwin or, if you already have cygwin installed, you still might need to install plug-ins listed below, if you do not have them already). Note that cygwin is now available in either 32 or 64 bit versions. The 64 bit version is preferred (if you can use it), but both should work.
- Follow the default options until you reach the "Packages" step of the cygwin setup wizard. In that step, expand the "Devel" category and select:
- g++ - the gnu c++ compiler
- gdb - the gnu debugger (optional)
- make - program for making files (the OSParticulas, NairnMPM, and NairnFEA binaries)
- Subversion - the version control system needed to download code from google.code.
- Next, expand the "Net" category and select:
- openssh - ssh command for secure remote connections (optional).
- Finally, expand the "Editors" section and select a command-line editer (e.g., vim). Such an editor is useful because editing cygwin files with Microsoft software (e.g., NotePad) can seriously corrupt files by changing line endings from Unix-style line feeds to Windows style carriage returns and line feeds.
The basic cygwin should now be set up. You can run it to open a cygwin command-line window and browse your files. By the default, all cygwin files will be in the folder C:\cygwin or C:\cygwin64 for the 64 bit version. Your home folder will usually be at /home/YOURUSERNAME.
Installing xerces
The first time you download the project, you will need to install xerces in your cygwin environment (if you already have xerces installed, you can skip to compiling now). You have two options. The simplest is to grab the xerces binary from cygwin:
- Run the cygwin setup application used to install and update cygwin.
- Expand the "Libs" section and look for libxerces-c-devel. Click to install it and make sure it is least version 3 (if not you have to compile as explained below). You have to get the "devel" version because that will install header files that are needed to compile the code engines.
- Finish the install. The library will be installed in /lib and the header files will be in /usr/include.
If the binary option version is out of date or if you prefer to build your own binaries, your second option is build the xerces library as follows:
- Download the xerces source code, which will be in a file such as xerces-c-3.x.x.tar.gz (with x being some numbers). Note that you should get the .tar.gz file instead of the .zip version because the .zip version has DOS files with carriage returns and line feeds (either in the source or inserted by Windows' zip methods) that may complicate compiliation. The .tar.gz file is also smaller.
- Move the downloaded file to a folder such as your home directory with the cygwin folder.
- Start a cygwin shell and and extract the files with:
cd /path/to/folder/with/download gunzip xerces-c-3.x.x.tar.gz tar xvf xerces-c-3.x.x.tar
where the x's are replaced by numbers in your downloaded file and /path/to/folder/with/download is full cygwin path to the folder you used in the previous step (warning: the xerces install will fail if this full path contains any spaces). - Go to the new folder created in previous step and configure the code with:
cd xerces-c-3.x.x ./configure LDFLAGS=-no-undefined
This step will prepare the xerces source code for building. Note: if you get error messages saying that $'\r'$ command is not found it means your files are DOS files rather than Unix files. You need to go back to step 1 and get the .tar.gz file this time. Note: the LDFLAGS=-no-undefined option may not be allowed in g++ 4.6.0 or newer. You can try without it or install the binary instead.
- When this configuring step is done, enter the commands
cd src make
This step will compile xerces and save the librarys in the xerces-c-3.x.x/.libs folder. - Finally, enter the command make install (still in the same folder). This step will install the compiled xerces libraries and needed header files in the default locations of /usr/local/lib and /usr/local/include folders, respectively.
Note the the above two options happen to install the xerces library and the header files in different locations. Because of this difference, you have to specify which option you used when compiling the code, as explained in the next section.
Compiling in cygwin
You are now ready to compile the nairn-mpm-fea code. In a cygwin shell, navigate to the checked out nairn-mpm-fea folder and proceed as follows. To compile OSParticulas and NairnMPM when using a binary install of xerces, use:
cd nairn-mpm-fea/NairnMPM/build make SYSTEM=cygwinbin
and to compile NairnFEA use:
cd nairn-mpm-fea/NairnFEA/build make SYSTEM=cygwinbin
If you compiled the xerces library manually, you should change the SYSTEM option to be SYSTEM=cygwin instead. All source code will be compiled and the executables will be installed in nairn-mpm-fea/NairnMPM/input or nairn-mpm-fea/NairnFEA/input, respectively. You can use an additional make install command to copy each compiled executable to your ~/bin folder if desired.
You can pass additional parameters to the make command to alter the compilation process if desired. See comments in the makefile for all the possible compilation options.
Trouble Shooting
- If the command-line compile does not work, the most likely explanation is a problem with the xerces installation. You either have to install it as specified above or edit the makefile to recognize your custom installation. The process is documented in the makefile and involves editing the xercesSo and headersPath variables for your different settings.
- Another conflict that has appeared in some Windows installations results in a linking error about undefined references to typeinfo. This error is a dynamic linking problem. It can be fixed by compiling xerces manually, deleting the dynamic library at /usr/local/lib/libxerces-c.dll.a, and then use the make SYSTEM=cygwin command to link again. This change will cause the code to link statically. The resulting executables will be much larger but should work fine.