Difference between revisions of "Compiling in Windows"

From OSUPDOCS
Jump to navigation Jump to search
 
(14 intermediate revisions by the same user not shown)
Line 7: Line 7:
  https://www.visualstudio.com/vs/community/
  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.
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 ===
=== Installing Xerces ===
Line 16: Line 16:
<li>Got to the [http://xerces.apache.org/xerces-c/ xerces web site].</li>
<li>Got to the [http://xerces.apache.org/xerces-c/ xerces web site].</li>
<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>
<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>
<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 in the same folder as the <tt>OSParticulas</tt> project folder.</li>
<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>
<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." This number may change if new "Visual Studios" are made available.</li>
<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>
<li>After loaded, select the <tt>XercesLib</tt> project.</li>
<li>After loaded, select the <tt>XercesLib</tt> project.</li>
<li>Select "Release" target for "x64" platform in the tool bar (these instructions assume you want 64-bit builds, which are recommended).</li>
<li>Select "Release" target for "x64" platform in the tool bar (these instructions assume you want 64-bit builds, which are recommended).</li>
Line 52: Line 52:
=== Windows Development ===
=== Windows Development ===


When developing code in Windows using Visual Studio, several other applications (all free) are helpful:
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


# [https://desktop.github.com/ GitHub] - for cloning the <tt>nairn-fea-mpm</tt> source code project.
# <tt>xerces-c_3_1.dll</tt> - this <tt>dll</tt>is created when you [[#Installing Xerces|build xerces]].
# [http://www.oracle.com/technetwork/java/javase/overview/index.html Java SE] - you must install Java (get at least version 7, but newer is preferred) to be able to run [[NairnFEAMPMViz]].
# <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.
# [https://www.eclipse.org/ide/ Eclipse IDE for Java] - for development of the [[NairnFEAMPMViz]] app and you will need to be sure your [http://www.oracle.com/technetwork/java/javase/overview/index.html Java SE install] included the <tt>JDK</tt> or development kit as well.
# <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.
# [https://tortoisesvn.net/ TortoiseSVN] - for those checking out [[OSParticulas]] project.
# [https://notepad-plus-plus.org/ NotePad++] - useful app for editing text files; a <tt>diff</tt> plug-in can be used to compare two versions of files.


== Using Eclipse IDE ==
== Using Eclipse IDE or cygwin ==


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| compiling using Eclipse IDE]].
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]].
 
== Using cygwin ==
 
A third approach to compiling in Windows is to install <tt>cygwin</tt>. This software gives you a Linux/Unix style environment and can work with software by means very similar to using Linux (or Mac in Unix mode). <font color="red">Note: use of <tt>cygwin</tt> is no longer recommended and has not be testted in a long time &mdash; you should switch to [[Using Visual Studio|Visual Studio compiling]] instead.</font> First, the code compiled in <tt>cygwin</tt> seems to run slower than code compiled in Visual Studio on the same machine. Second, when running calculations using the <tt>NairnFEAMPMViz</tt> app, a bug in Java disables the useful feature in that software to abort calculations before they are done. This bug is avoided when using code compiled in Visual Studio. The remainder of this section should not be used, but it has been left in place for previous users (or anyone that really wants to work in <tt>cygwin</tt>).
 
=== Installing and Setting Up cygwin ===
 
The <tt>nairn-mpm-fea</tt> project runs well in Windows by using the [http://www.cygwin.com <tt>cygwin</tt>] system. You can [[Download Source Code|check out]] the project, compile the code, [[Options for Running Calculations|run calculations]], and visualize the results. This section gives the step-by-step process for the required <tt>cygwin</tt> 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 [http://www.cygwin.com <tt>cygwin setup.exe</tt>] application and run it (to install <tt>cygwin</tt> or, if you already have <tt>cygwin</tt> installed, you still might need to install plug-ins listed below, if you do not have them already). Note that <tt>cygwin</tt> 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 <tt>cygwin</tt> setup wizard. In that step, expand the "Devel" category and select:
#* <tt>g++</tt> - the gnu c++ compiler
#* <tt>gdb</tt> - the gnu debugger (optional)
#* <tt>make</tt> - program for making files (the [[OSParticulas]], [[NairnMPM]], and [[NairnFEA]] binaries)
#* <tt>Subversion</tt> - the version control system needed to [[Download Source Code|download code]] from <tt>google.code</tt>.
# Next, expand the "Net" category and select:
#* <tt>openssh</tt> - ssh command for secure remote connections (optional).
# Finally, expand the "Editors" section and select  a command-line editer (<i>e.g.</i>, <tt>vim</tt>). Such an editor is useful because editing <tt>cygwin</tt> files with Microsoft software (''e.g.'', <tt>NotePad</tt>) can seriously corrupt files by changing line endings from Unix-style line feeds to Windows style carriage returns and line feeds.
 
The basic <tt>cygwin</tt> should now be set up. You can run it to open a <tt>cygwin</tt> command-line window and browse your files. By the default, all <tt>cygwin</tt> files will be in the folder <tt>C:\cygwin</tt> or <tt>C:\cygwin64</tt> for the 64 bit version. Your home folder will usually be at <tt>/home/YOURUSERNAME</tt>.
 
=== Installing xerces ===
 
The first time you [[Download Source Code|download the project]], you will need to install <tt>xerces</tt> in your <tt>cygwin</tt> environment (if you already have <tt>xerces</tt> installed, you can [[#Compiling in cygwin|skip to compiling]] now). You have two options. The simplest is to grab the <tt>xerces</tt> binary from <tt>cygwin</tt>:
 
# Run the <tt>cygwin</tt> setup application used to install and update <tt>cygwin</tt>.
# Expand the &quot;Libs&quot; section and look for <tt>libxerces-c-devel</tt>. 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 [[#Compiling in cygwin|compile the code engines]].
# Finish the install. The library will be installed in <tt>/lib</tt> and the header files will be in <tt>/usr/include</tt>.
 
If the binary option version is out of date or if you prefer to build your own binaries, your second option is build the <tt>xerces</tt> library as follows:
 
<ol>
<li>[http://xerces.apache.org/xerces-c/download.cgi Download the <tt>xerces</tt> source code], which will be in a file such as <tt>xerces-c-3.x.x.tar.gz</tt> (with <tt>x</tt> being some numbers). Note that you should get the <tt>.tar.gz</tt> file instead of the <tt>.zip</tt> version because the <tt>.zip</tt> 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 <tt>.tar.gz</tt> file is also smaller.</li>
 
<li>Move the downloaded file to a folder such as your home directory with the <tt>cygwin</tt> folder.</li>
<li>Start a <tt>cygwin</tt> shell and and extract the files with:
<pre>
cd /path/to/folder/with/download
gunzip xerces-c-3.x.x.tar.gz
tar xvf xerces-c-3.x.x.tar</pre>
where the <tt>x</tt>'s are replaced by numbers in your downloaded file and <tt>/path/to/folder/with/download</tt> is full <tt>cygwin</tt> path to the folder you used in the previous step (<font color="red">warning</font>: the <tt>xerces</tt> install will fail if this full path contains any spaces).</li>
 
<li>Go to the new folder created in previous step and configure the code with:
<pre>
cd xerces-c-3.x.x
./configure LDFLAGS=-no-undefined
</pre>
This step will prepare the <tt>xerces</tt> 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 <tt>1</tt> and get the <tt>.tar.gz</tt> file this time. Note: the <tt>LDFLAGS=-no-undefined</tt> option may not be allowed in g++ 4.6.0 or newer. You can try without it or [[#Installing xerces|install the binary]] instead.
</li>
 
<li>When this configuring step is done, enter the commands
<pre>
cd src
make</pre>
This step will compile <tt>xerces</tt> and save the librarys in the <tt>xerces-c-3.x.x/.libs</tt> folder.</li>
 
<li>Finally, enter the command <tt>make install</tt> (still in the same folder). This step will install the compiled <tt>xerces</tt> libraries and needed header files in the default locations of <tt>/usr/local/lib</tt> and <tt>/usr/local/include</tt> folders, respectively.</li>
 
</ol>
 
Note the the above two options happen to install the <tt>xerces</tt> library and the header files in different locations. Because of this difference, you have to specify which option you used when [[#Compiling in cygwin|compiling the code]], as explained in the next section.
 
=== Compiling in cygwin ===
 
You are now ready to compile the <tt>nairn-mpm-fea</tt> code. In a <tt>cygwin</tt> shell, navigate to the checked out <tt>nairn-mpm-fea</tt> folder and proceed as follows. To compile [[OSParticulas]] and [[NairnMPM]] when using a binary install of <tt>xerces</tt>, 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 <tt>xerces</tt> library manually, you should change the <tt>SYSTEM</tt> option to be <tt>SYSTEM=cygwin</tt> instead. All source code will be compiled and the executables will be installed in <tt>nairn-mpm-fea/NairnMPM/input</tt> or <tt>nairn-mpm-fea/NairnFEA/input</tt>, respectively. You can use an additional <tt>make install</tt> command to copy each compiled executable to your <tt>~/bin</tt> folder if desired.
 
You can pass additional parameters to the <tt>make</tt> command to alter the compilation process if desired. See comments in the <tt>makefile</tt> 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 <tt>xerces</tt> installation. You either have to install it as specified [[#Installing xerces|above]] or edit the <tt>makefile</tt> to recognize your custom installation. The process is documented in the <tt>makefile</tt> and involves editing the <tt>xercesSo</tt> and <tt>headersPath</tt> variables for your different settings.
#Another conflict that has appeared in some  Windows installations results in a linking error about undefined references to <tt>typeinfo</tt>. This error is a dynamic linking problem. It can be fixed by [[#Installing xerces|compiling <tt>xerces</tt> manually]], deleting the dynamic library at <tt>/usr/local/lib/libxerces-c.dll.a</tt>, and then use the <tt>make SYSTEM=cygwin</tt> command to link again. This change will cause the code to link statically. The resulting executables will be much larger but should work fine.

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.