Difference between revisions of "Compiling in MacOS X"
(Created page with "This page explains two ways to compile using MacOS X. A third option is to [[|compile using Eclipse]]. == Using XCode == Most development of OSParticulas/NairnMPM an...") |
|||
Line 1: | Line 1: | ||
This page explains | This page explains several methods to [[Compile the Code Engines|compile code engines]] using MacOS X. | ||
== Using XCode == | == Using XCode == | ||
Most development of [[OSParticulas]]/[[NairnMPM]] and [[NairnFEA]] is done in MacOS X and thus compiling on MacOS X is easy. The preferred method is to use XCode | Most development of [[OSParticulas]]/[[NairnMPM]] and [[NairnFEA]] is done in MacOS X and thus compiling on MacOS X is easy. The preferred method is to use XCode. A complete XCode project is located at | ||
nairn-mpm-fea/Common/Projects/NairnMPM.xcodeproj | nairn-mpm-fea/Common/Projects/NairnMPM.xcodeproj | ||
This project is called <tt>NairnMPM</tt>, but it includes all MPM and FEA source code in two targets named <tt>NairnMPM</tt> and <tt>NairnFEA</tt>. Once [[#Compiling Xerces on MacOS X|<tt>xerces</tt> is installed]], open the <tt>NairnMPM.xcodeproj</tt> to compile the code by: | This project is called <tt>NairnMPM</tt>, but it includes all MPM and FEA source code in two targets named <tt>NairnMPM</tt> and <tt>NairnFEA</tt>. Once [[#Compiling Xerces on MacOS X|<tt>xerces</tt> is installed]], open the <tt>NairnMPM.xcodeproj</tt> to compile the code by: | ||
# Select the target to compile - either <tt>NairnMPM</tt> or <tt>NairnFEA</tt> | # Select the target to compile - either <tt>NairnMPM</tt> or <tt>NairnFEA</tt> | ||
# Choose build and they will compile and saved in XCode's derived data folder. | # Choose build and they will compile and be saved in XCode's derived data folder. | ||
If a linking error occurs, you might have conflicting architectures between the XCode settings and the [[#Compiling Xerces on MacOS X|<tt>xerces</tt> library you installed]]. To fix this problem edit <i>both</i> the project and target settings and under the "Architectures" section, set the "Architectures" option to match the architecture you used when [[#Compiling Xerces on MacOS X|installing <tt>xerces</tt>]] or recompile <tt>xerces</tt> if needed. | If a linking error occurs, you might have conflicting architectures between the XCode settings and the [[#Compiling Xerces on MacOS X|<tt>xerces</tt> library you installed]]. To fix this problem edit <i>both</i> the project and target settings and under the "Architectures" section, set the "Architectures" option to match the architecture you used when [[#Compiling Xerces on MacOS X|installing <tt>xerces</tt>]] or recompile <tt>xerces</tt> if needed. | ||
== Compiling Xerces on MacOS X == | == Compiling Xerces on MacOS X == | ||
Before you can compile and run the project, however, you will need an installed version of the <tt>xerces</tt> library and a copy of the <tt>xerces</tt> header files. | Before you can compile and run the project, however, you will need an installed version of the <tt>xerces</tt> library and a copy of the <tt>xerces</tt> header files. These compiling instructions assume they are installed in the default locations for MacOS X or at: | ||
/usr/local/lib/libxerces-c.dylib | /usr/local/lib/libxerces-c.dylib | ||
Line 25: | Line 25: | ||
for the header files. These can be changed if needed by editing the project and target settings. Since revision 274 of the <code>nairn-mpm-fea</code> project, this library must be <tt>xerces 3.0</tt> or newer; prior to that revision, it had be <tt>xerces 2.8</tt> or older. These libraries can be obtained by downloading the | for the header files. These can be changed if needed by editing the project and target settings. Since revision 274 of the <code>nairn-mpm-fea</code> project, this library must be <tt>xerces 3.0</tt> or newer; prior to that revision, it had be <tt>xerces 2.8</tt> or older. These libraries can be obtained by downloading the | ||
[http://xml.apache.org/xerces-c/index.html | [http://xml.apache.org/xerces-c/index.html xerces source code] from the [http://www.apache.org/ Apache Software Foundation] web site and then building and installing <tt>xerces</tt> with the following steps (after seeing potential [[#MacOS X Lion or Newer Command Line Tools|startup issues on Lion or newer systems]]): | ||
<ol> | <ol> | ||
Line 42: | Line 42: | ||
== MacOS X Command Line Compiling == | == MacOS X Command Line Compiling == | ||
It is easy to compile on MacOS X using a command line approach (after seeing potential [[#MacOS X Lion or Newer Command Line Tools|startup issues on Lion or newer systems]]). First (and first time only) install <tt>xerces</tt> and its header files as [[#Compiling Xerces on MacOS X|explained above]] and make sure they are in the specified default locations. Once <tt>xerces</tt> is ready, you compile | It is easy to compile on MacOS X using a command line approach (after seeing potential [[#MacOS X Lion or Newer Command Line Tools|startup issues on Lion or newer systems]]). First (and first time only) install <tt>xerces</tt> and its header files as [[#Compiling Xerces on MacOS X|explained above]] and make sure they are in the specified default locations. Once <tt>xerces</tt> is ready, you compile [[OSParticulas]] or [[NairnMPM]] using: | ||
<pre>cd nairn-mpm-fea/NairnMPM/build | <pre>cd nairn-mpm-fea/NairnMPM/build | ||
make SYSTEM=mac | make SYSTEM=mac | ||
</pre> | </pre> | ||
and compile | and compile [[NairnFEA]] using: | ||
<pre>cd nairn-mpm-fea/NairnFEA/build | <pre>cd nairn-mpm-fea/NairnFEA/build | ||
make SYSTEM=mac | make SYSTEM=mac | ||
</pre> | </pre> | ||
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. | 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. | ||
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 [[#Compiling Xerces on MacOS X|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. | 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 [[#Compiling Xerces on MacOS X|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. | ||
You can pass additional parameters to the <tt>make</tt> command to alter the compilation process. See comments in the <tt>makefile</tt> for all the latest options. | |||
== Using Eclipse IDE == | |||
Because the Eclipse IDE can run on multiple platforms, you can use it on Mac OS X for compiling as well. For detains, see help on [[Compiling Using Eclipse IDE| compiling using Eclipse IDS]]. | |||
== MacOS X Lion or Newer Command Line Tools == | == MacOS X Lion or Newer Command Line Tools == | ||
Line 66: | Line 70: | ||
# You probably have to install XCode (even if you do not plan to use it). | # You probably have to install XCode (even if you do not plan to use it). | ||
# In XCode, use its preferences window to install "Command Line Tools". | # In XCode, use its preferences window to install "Command Line Tools". | ||
# Most tools should now be available. You should be able to make and install the <tt>xerces</tt> project and then use the provided XCode project to build | # Most tools should now be available. You should be able to make and install the [[#Compiling Xerces on MacOS X|<tt>xerces</tt>]] project and then use the provided [[#Using XCode|XCode project]] to build [[OSParticulas]], [[NairnMPM]], and [[NairnFEA]]. | ||
One issue in the XCode project is that it might not find your <tt>xerces</tt> library, even if it is in the standard location. If it is not found, the library will be in <font color="red">red</font> in the "External Frameworks and Libraries" folder. You have to select the library, view its properties, and then click to set the path on your computer. The problem is that you cannot navigate to the <tt>/usr/local/lib</tt> folder anymore (another new Apple "feature"). Here is a trick to get there: | One issue in the XCode project is that it might not find your <tt>xerces</tt> library, even if it is in the standard location. If it is not found, the library will be in <font color="red">red</font> in the "External Frameworks and Libraries" folder. You have to select the library, view its properties, and then click to set the path on your computer. The problem is that you cannot navigate to the <tt>/usr/local/lib</tt> folder anymore (another new Apple "feature"). Here is a trick to get there: |
Revision as of 09:01, 28 August 2013
This page explains several methods to compile code engines using MacOS X.
Using XCode
Most development of OSParticulas/NairnMPM and NairnFEA is done in MacOS X and thus compiling on MacOS X is easy. The preferred method is to use XCode. A complete XCode project is located at
nairn-mpm-fea/Common/Projects/NairnMPM.xcodeproj
This project is called NairnMPM, but it includes all MPM and FEA source code in two targets named NairnMPM and NairnFEA. Once xerces is installed, open the NairnMPM.xcodeproj to compile the code by:
- Select the target to compile - either NairnMPM or NairnFEA
- Choose build and they will compile and be saved in XCode's derived data folder.
If a linking error occurs, you might have conflicting architectures between the XCode settings and the xerces library you installed. To fix this problem edit both the project and target settings and under the "Architectures" section, set the "Architectures" option to match the architecture you used when installing xerces or recompile xerces if needed.
Compiling Xerces on MacOS X
Before you can compile and run the project, however, you will need an installed version of the xerces library and a copy of the xerces header files. These compiling instructions assume they are installed in the default locations for MacOS X or at:
/usr/local/lib/libxerces-c.dylib
for the library and at
/usr/local/include
for the header files. These can be changed if needed by editing the project and target settings. Since revision 274 of the nairn-mpm-fea
project, this library must be xerces 3.0 or newer; prior to that revision, it had be xerces 2.8 or older. These libraries can be obtained by downloading the
xerces source code from the Apache Software Foundation web site and then building and installing xerces with the following steps (after seeing potential startup issues on Lion or newer systems):
- Open Terminal app and navigate to the xerces source folder expanded from the downloaded file.
- Configure the code with the command:
./configure CFLAGS="-arch x86_64" CXXFLAGS="-arch x86_64"
where the provided arch (or architecture) is the desired option for your machine. The main Mac options are i386 for 32 bit Intel processors, x86_64 for 64 bit Intel processors, ppc for 32 bit PowerPC chips, or ppc64 for 64 bit PowerPC64 chips. Although i386 will work on any Intel processor, you should use x86_64 if you have a 64 bit processor, because the code will run faster. To determine how many bits your Intel chip has, chose "About This Mac" from the Apple menu, click "More Info..." button, and look up the processor name in the hardware section. The "Intel Core Solo" and "Intel Core Duo" are 32 bit chips and most others are 64 bit chips. - When the configuration is done, use the following commands:
cd src make make install
These commands make the library (but not the unneeded xerces examples). The final install command after make is done, installs both the library and the header files at the default locations listed above. If the make install shows a permission error, you can solve that by using sudo make install instead and provide your administrator password. - When working with nairn-mpm-fea on a new Mac, the xerces installation only needs to be done once. The only reason to repeat it is when a new xerces version is available and/or the project requires a new version for compatibility.
MacOS X Command Line Compiling
It is easy to compile on MacOS X using a command line approach (after seeing potential startup issues on Lion or newer systems). First (and first time only) install xerces and its header files as explained above and make sure they are in the specified default locations. Once xerces is ready, you compile OSParticulas or NairnMPM using:
cd nairn-mpm-fea/NairnMPM/build make SYSTEM=mac
and compile NairnFEA using:
cd nairn-mpm-fea/NairnFEA/build make SYSTEM=mac
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.
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.
You can pass additional parameters to the make command to alter the compilation process. See comments in the makefile for all the latest options.
Using Eclipse IDE
Because the Eclipse IDE can run on multiple platforms, you can use it on Mac OS X for compiling as well. For detains, see help on compiling using Eclipse IDS.
MacOS X Lion or Newer Command Line Tools
Apple choose not to install command line tools on Lion (or newer systems such as Mountain Lion) and makes it hard to access some very useful folders (such as your home "Library" folder). With these changes, you cannot compile nairn-fea-mpm code engines or xerces or until you do some additional set up:
- You probably have to install XCode (even if you do not plan to use it).
- In XCode, use its preferences window to install "Command Line Tools".
- Most tools should now be available. You should be able to make and install the xerces project and then use the provided XCode project to build OSParticulas, NairnMPM, and NairnFEA.
One issue in the XCode project is that it might not find your xerces library, even if it is in the standard location. If it is not found, the library will be in red in the "External Frameworks and Libraries" folder. You have to select the library, view its properties, and then click to set the path on your computer. The problem is that you cannot navigate to the /usr/local/lib folder anymore (another new Apple "feature"). Here is a trick to get there:
- In the Finder, use the "Go to Folder..." menu command and enter "/usr/local".
- After it opens, choose the "Add To Sidebar" menu command. This folder will now appear in all file selection boxes.
- Go back to XCode and enter box to select the path the the xerces library.
- Go through your new "local" folder and select the xerces library file in /usr/local/lib.
Apple seems to creating road blocks to keep you from using you computer for interesting programming. With a few tricks it is still possible to get around their road blocks. Hopefully these tricks will continue to work in the future.