Difference between revisions of "Compiling in Windows"

From OSUPDOCS
Jump to navigation Jump to search
 
(97 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Windows Using cygwin ==
This page explains how to [[Compile the Code Engines|compile code engines]] using Windows.


To compile and run in Windows, you need some kind of Linux/Unix environment. The recommended option is to use [http://www.cygwin.com <tt>cygwin</tt>] and this documentation is based on its use. This process has been verified in both Windows XP, Windows Vista and Windows 7 (although you may need the latest <tt>cygwin</tt> 1.7 for Windows 7).
== Using Visual Studio ==


== Installing and Setting Up cygwin ==
Development of [[NairnMPM]] and [[NairnFEA]] in Windows is best done 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:


The `nairn-mpm-fea` projects run well in Windows by using the <a href="http://www.cygwin.com">cygwin</a> system. You can download this project, compile the code, run calculations, and visualize the results.
https://www.visualstudio.com/vs/community/
First you need to set up your computer to use [http://www.cygwin.com <tt>cygwin</tt>].


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. See [[Mac/Windows Requirements]] for additional installations that might be needed for development in Windows.


= Setting up `cygwin` =
=== Installing Xerces ===


The recommended approach to using `nairn-mpm-fea` in Windows is to use `cygwin` and this page gives the step-by-step process for the required 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).
Before you can compile and run the project, however, you will need a compiled version of the <tt>xerces-c_#_#.dll</tt> library (where <tt>#_#</tt> is version number) and a copy of the <tt>xerces</tt> header files. These needed components are installed as follows:


  # Download the <a href="http://www.cygwin.com">cygwin setup.exe</a> 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).
<ol>
  # Follow the default options until you reach the "Packages" step of the `cygwin` setup wizard. In that step, expand the "Devel" category and select:
<li>Got to the [http://xerces.apache.org/xerces-c/ xerces web site].</li>
    * `g++` - the gnu c++ compiler
<li>Go to "Download" section and get source distribution zip file, which contains VS projects (these notes used version 3.1.4; some more recent versions do not have VS projects, but you can get 3.1.4, or maybe a newer one with projects, from the download archives).</li>
    * `gdb` - the gnu debugger (optional)
<li>Extract the contents of the zip file and place the resulting xerces folder in the same folder as the <tt>GitHib</tt> folder that contains the <tt>nairn-fea-mpm</tt> project folder. For <tt>OSParticulas</tt>, put the xerces folder in the same folder as the <tt>OSParticulas</tt> project folder.</li>
    * `make` - program for making files (the `NairnMPM` and `NairnFEA` binaries)
<li>Open the Visual Studio solution in <tt>xerces</tt> project folder at <tt>projects\Win32\VC14\xerces-all\xerces-all.sln</tt> (be sure not to open the <tt>xerces-all</tt> file one level higher, because it does not work). This step is using "VS14" because it corresponds to the version supplied with "Visual Studio Community 2015" (and works with "Visual Studio 2019" with automatic update). This number may change if new "Visual Studios" are made available.</li>
    * `Subversion` - the version control system needed to download code from `GoogleCode.com`.
<li>After loaded, select the <tt>XercesLib</tt> project.</li>
  # Next, expand the "Net" category and select:
<li>Select "Release" target for "x64" platform in the tool bar (these instructions assume you want 64-bit builds, which are recommended).</li>
    * `openssh` - ssh command for secure remote connections (optional).
<li>Build the project. The compiled <tt>xerces-c_3_1.dll</tt> file will be written to <tt>Build\Win64\VC14\Release</tt> in the <tt>xerces</tt> folder (numbers may change if <tt>xerces</tt> version number changes).
  # 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 for Unix-style line feeds to Windows style carriage returns and line feeds.
</ol>


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`. Your home folder will usually be at `/home/YOURUSERNAME`. You are now ready to [Download_Project download the code].
=== Compile NairnMPM, NairnFEA, and other tools ===


== Installing xerces ==
To compile all code binaries in Visual Studio:
 
The first time you download the project, you will need to install <code>xerces</code> in your [http://www.cygwin.com <tt>cygwin</tt>] environment (if you already have xerces installed, you can <a href="#cygcc">skip to compiling now</a>). Although [http://www.cygwin.com <tt>cygwin</tt>] has an option to install the <code>xerces</code> binary, it usually has an out-dated version. You therefore will need to download the <code>xerces</code> source code, build it, and install it. Since revision 274 of the <code>nairn-mpm-fea</code> project, the code requires <code>xerces 3.0</code> or newer. The procedure for <code>xerces 3.0</code> or newer is:</p>


<ol>
<ol>
<li><a href="http://xerces.apache.org/xerces-c/download.cgi">Download the <code>xerces</code> source code</a>, which will be in a file such as <code>xerces-c-3.x.x.tar.gz</code> (with <code>x</code> being some numbers). Note that you should get the <code>.tar.gz</code> file instead of the <code>.zip</code> version because the <code>.zip</code> 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 <code>.tar.gz</code> file is also smaller.</li>
<li>Open the Visual Studio solution at <tt>Common\Projects\VS\NairnMPM\NairnMPM.sln</tt> in the <tt>nairn-fea-mpm</tt> project.</li>
<li>To compile [[NairnMPM]], [[NairnFEA]], [[ExtractMPM]], and [[CompareGlobal]], click on each project and select to build that project from the Build menu.</li>
<li>The compiled results will be in the <tt>Common\Projects\VS\NairnMPM\Build\Release-x64</tt> folder. If the compile fails, see below.</li>
</ol>


<li>Move the downloaded file to a folder such as the root <code>cygwin</code> folder, which by default is at Windows path <code>C:\cygwin\</code> (<font color="red">warning</font>: the <code>xerces</code> install will fail if the path to the folder in <code>cygwin</code> contains any spaces; if you use the recommended root folder, the path will be &quot;<code>/</code>&quot; which has no spaces and is therefore safe).</li>
The above builds will fail if you are using a different version of Visual Studio and/or different version of Windows. They may also fail if the project cannot find <tt>xerces</tt> header files or the <tt>xerces</tt> library file. Here are some project settings you may need to customize to work on your computer::
<li>Start a <code>cygwin</code> shell and and extract the files with:
<pre>
cd /
gunzip xerces-c-3.x.x.tar.gz
tar xvf xerces-c-3.x.xtar</pre>
where the <code>x</code>'s are replaced by numbers in your downloaded file.</li>


<li>Go to the new folder and configure the code with:
<ol>
<pre>
<li>Click on the project you are compiling (<i>e.g.</i>, [[NairnMPM]]) and then select Project&rarr;Properties... menu command (or right click the project and pick "Properties" from the pop-up menu).</li>
cd xerces-c-3.x.x
<li> Clock on General and:
./configure LDFLAGS=-no-undefined
<ul>
</pre>
<li>Set Target Platform and Target Platform Version to work on your computer</li>
This step will prepare the <code>xerces</code> 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. Consult a Unix expert on how to fix them or go back to step <code>1</code> and get the <code>.tar.gz</code> file this time.
<li>Set Platform Toolset to one available on your computer</li>
</ul></li>
<li>Click on "VC++ Directories" and change the xerces entry in "Include Directories" to point to <tt>src</tt> folder in the downloaded <tt>xerces</tt> project on your computer. The checked-out project assumes the <tt>xerces</tt> folder is in the same folder as the checked out <tt>nairn-fea-mpm</tt> folder, but you can store it elsewhere if you prefer.</li>
<li>Expand "Linker" section, click on "General," and change the xerces entry in "Additional Library Directories" to be path on your computer to the [[#Installing Xerces|folder with the compiled xerces library]].</li>
<li>Repeat for other projects as needed.
</li>
</li>
<li>When this configuring step is done, enter the commands
<pre>
cd src
make</pre>
This step will compile <code>xerces</code> and save the librarys in the <code>xerces-c-3.x.x/.libs</code> folder.</li>
<li>Finally, enter the command &quot;<code>make install</code>&quot; (still in the same folder). This step will install the compiled <code>xerces</code> libraries and needed header files in the default locations of <code>/usr/local/lib</code> and <code>/usr/local/include</code> folders, respectively.</li>
</ol>
</ol>


<p><a name="cygcc"></a>You are now ready to compile the <code>nairn-mpm-fea</code> code. In a <code>cygwin</code> shell, navigate to the checked out <code>nairn-mpm-fea</code> and proceed as follows. To compile <code>NairnMPM</code> use:</p>
You should now be able to build [[NairnMPM]] and [[NairnFEA]] code engines and the results will be in the <tt>Common\Projects\VS\NairnMPM\Build\Release-x64</tt> folder. See [[Options for Running Calculations]] to start running calculations. You can also build the [[ExtractMPM]] and [[CompareGlobal]] tools and their executable will be in the same output folder.
 
<pre>
cd nairn-mpm-fea/NairnMPM/build
make SYSTEM=cygwin
</pre>


<p>and to compile <code>NairnFEA</code> use:</p>
=== Windows Development ===


<pre>
To run the compiled code, you need to provide all the required <tt>dll</tt>s. You can move them all to any folder, but it is convenient to keep then in the build folder at <tt>Common\Projects\VS\NairnMPM\Build\Release-x64</tt>. The needed <tt>dll</tt> files are
cd nairn-mpm-fea/NairnFEA/build
make SYSTEM=cygwin
</pre>


<p>All source code will be compiled and the executables will be installed in <code>nairn-mpm-fea/NairnMPM/input</code> or <code>nairn-mpm-fea/NairnFEA/input</code>, respectively. You can use an additional '<code>make install</code>' command to copy each compiled executable to your <code>~/bin</code> folder if desired.
# <tt>xerces-c_3_1.dll</tt> - this <tt>dll</tt>is created when you [[#Installing Xerces|build xerces]].
</p>
# <tt>vsruntime140.dll</tt> and <tt>msvcp140.dll</tt> - these <tt>dll</tt>s are to run compiled C++ code and can be copied from the Visual Studio <tt>Redist</tt> folder. Be sure to get the x64 versions.
# <tt>vcomp140.dll</tt> - this <tt>dll</tt> is for OpenMP to run in parallel and can be copied from the Visual Studio <tt>Redist</tt> folder. Be sure to get the x64 versions.


<p>If the command-line compile does not work, the most likely explanation is a problem with the <code>xerces</code> installation. You either have to install it as specified above or edit the <code>makefile</code> to recognize your custom installation. The process is documented in the <code>makefile</code> and involves editing the <code>xercesSo</code> and <code>headersPath</code> variables for your different settings. Another possible reason is a potential conflict with some <code>cygwin</code>/Windows combinations. If you get a linking error about undefined references to <code>typeinfo</code>, you have encountered a dynamic linking problem. It can be fixed by deleting the dynamic library at <code>/usr/local/lib/libserces-c.dll.a</code> and then use the '<code>make SYSTEM=cygwin</code>' command to link again. This change will cause the code to link statically. The resulting executables will be much larger but should work fine.
== Using Eclipse IDE or cygwin ==
</p>


<p>Once the code is compiled, do a <a href="../running/index.html">test run</a> to verify it worked.
While it might be possible to compile using <tt>Eclipse</tt>, the process is no longer supported. Similarly, use of <tt>cygwin</tt> is no longer supported. The method was cumbersome and the compiled executables run much more slowly then when compiled using Visual Studio. Windows compiling should [[#Using Visual Studio|use Visual Studio]].
</p>

Latest revision as of 13:09, 17 December 2021

This page explains how to compile code engines using Windows.

Using Visual Studio

Development of NairnMPM and NairnFEA in Windows is best done 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. See Mac/Windows Requirements for additional installations that might be needed for development in Windows.

Installing Xerces

Before you can compile and run the project, however, you will need a compiled version of the xerces-c_#_#.dll library (where #_# is version number) and a copy of the xerces header files. These needed components are installed as follows:

  1. Got to the xerces web site.
  2. Go to "Download" section and get source distribution zip file, which contains VS projects (these notes used version 3.1.4; some more recent versions do not have VS projects, but you can get 3.1.4, or maybe a newer one with projects, from the download archives).
  3. Extract the contents of the zip file and place the resulting xerces folder in the same folder as the GitHib folder that contains the nairn-fea-mpm project folder. For OSParticulas, put the xerces folder in the same folder as the OSParticulas project folder.
  4. Open the Visual Studio solution in xerces project folder at projects\Win32\VC14\xerces-all\xerces-all.sln (be sure not to open the xerces-all file one level higher, because it does not work). This step is using "VS14" because it corresponds to the version supplied with "Visual Studio Community 2015" (and works with "Visual Studio 2019" with automatic update). This number may change if new "Visual Studios" are made available.
  5. After loaded, select the XercesLib project.
  6. Select "Release" target for "x64" platform in the tool bar (these instructions assume you want 64-bit builds, which are recommended).
  7. Build the project. The compiled xerces-c_3_1.dll file will be written to Build\Win64\VC14\Release in the xerces folder (numbers may change if xerces version number changes).

Compile NairnMPM, NairnFEA, and other tools

To compile all code binaries in Visual Studio:

  1. Open the Visual Studio solution at Common\Projects\VS\NairnMPM\NairnMPM.sln in the nairn-fea-mpm project.
  2. To compile NairnMPM, NairnFEA, ExtractMPM, and CompareGlobal, click on each project and select to build that project from the Build menu.
  3. The compiled results will be in the Common\Projects\VS\NairnMPM\Build\Release-x64 folder. If the compile fails, see below.

The above builds will fail if you are using a different version of Visual Studio and/or different version of Windows. They may also fail if the project cannot find xerces header files or the xerces library file. Here are some project settings you may need to customize to work on your computer::

  1. Click on the project you are compiling (e.g., NairnMPM) and then select Project→Properties... menu command (or right click the project and pick "Properties" from the pop-up menu).
  2. Clock on General and:
    • Set Target Platform and Target Platform Version to work on your computer
    • Set Platform Toolset to one available on your computer
  3. Click on "VC++ Directories" and change the xerces entry in "Include Directories" to point to src folder in the downloaded xerces project on your computer. The checked-out project assumes the xerces folder is in the same folder as the checked out nairn-fea-mpm folder, but you can store it elsewhere if you prefer.
  4. Expand "Linker" section, click on "General," and change the xerces entry in "Additional Library Directories" to be path on your computer to the folder with the compiled xerces library.
  5. Repeat for other projects as needed.

You should now be able to build NairnMPM and NairnFEA code engines and the results will be in the Common\Projects\VS\NairnMPM\Build\Release-x64 folder. See Options for Running Calculations to start running calculations. You can also build the ExtractMPM and CompareGlobal tools and their executable will be in the same output folder.

Windows Development

To run the compiled code, you need to provide all the required dlls. You can move them all to any folder, but it is convenient to keep then in the build folder at Common\Projects\VS\NairnMPM\Build\Release-x64. The needed dll files are

  1. xerces-c_3_1.dll - this dllis created when you build xerces.
  2. vsruntime140.dll and msvcp140.dll - these dlls are to run compiled C++ code and can be copied from the Visual Studio Redist folder. Be sure to get the x64 versions.
  3. vcomp140.dll - this dll is for OpenMP to run in parallel and can be copied from the Visual Studio Redist folder. Be sure to get the x64 versions.

Using Eclipse IDE or cygwin

While it might be possible to compile using Eclipse, the process is no longer supported. Similarly, use of cygwin is no longer supported. The method was cumbersome and the compiled executables run much more slowly then when compiled using Visual Studio. Windows compiling should use Visual Studio.