Compiling Cloudy on OS X or MacOS
Install the Apple Command Line Tools
OS X and MacOS do not come installed with such tools as make and grep. You can get them, and the LLVM compiler, with the Apple Command Line Tools. This is available with Xcode (a very large download from the App Store) or by itself from the Developer website here. You do need to register on the Developer website to get the tools for free. Make sure you get the version of the download for your version of OS X or MacOS. The installation will create an alias called "gcc" which points to the LLVM compiler but it does not install gcc.
Recent versions of the LLVM compiler cannot build Cloudy C13.03 and before. It can build C13.04 and later. For more on this problem, see the FPE trapping section below. If you want to build C13.03 or before you need to use gcc or obtain an older version of LLVM.
The situation in early 2017
LLVM is the preferred and best-supported compiler under OS X. As described in the FPE trapping section below, more recent versions of LLVM had trouble and versions of Cloudy through 13.03 could not be built. We recommended using homebrew to install gcc. Versions of Cloudy after 13.03 have been modified to work with LLVM.
There currently is an incompatibility when installing both gcc and LLVM, as described in this bug report. For now, it is better to use LLVM from Apple and not install the homebrew gcc. Problems with LLVM can arise if you install homebrew gcc and have it on your path.
These problems may be fixed someday. For now, we leave the instructions for homebrew here, even though we do not recommend using it.
How to install gcc with Homebrew
The gcc compiler is used to develop and test Cloudy and is very reliable. It does not come with Xcode or the Apple Command Line Tools.
To install gcc on your Mac use a distribution manager such as Homebrew. Note that there does appear to be a version of gcc on Macs but that is aliased to LLVM since Apple no longer support gcc. But you can install a real gcc yourself.
Download and install Homebrew from http://brew.sh/. Next see which versions of gcc are available by doing
brew search gcc
It will reply with something like
gcc homebrew/versions/gcc43 homebrew/versions/gcc48 homebrew/versions/gcc44 homebrew/versions/gcc49 homebrew/versions/gcc45 homebrew/versions/llvm-gcc28 homebrew/versions/gcc46 homebrew/dupes/apple-gcc42 homebrew/versions/gcc47
Select one and install it by
brew install homebrew/versions/gcc48
This will take some time - about an hour on my Mac.
Next go to the /usr/local/bin directory, the location where Homebrew installs software, and do
ls gcc* g++*
which will result in something like
g++-4.8 gcc-4.8 gcc-ar-4.8 gcc-nm-4.8 gcc-ranlib-4.8
Cloudy will use g++ when it builds, so we will create an alias to g++-4.8 by doing
ln -s g++-4.8 g++
We should now have a working version of g++ in this directory. To test it do
You should get something like
g++ (Homebrew gcc48 4.8.3) 4.8.3 Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Next you need to make sure that we can find this version of g++ rather than the broken LLVM version. You will need to change your PATH so that /usr/local/bin comes before /usr/bin. Do this by adding the line
towards the end of your .profile file.
Versions 5.1 and later of Xcode are broken and cannot compile Cloudy versions up to and including C13.03. Find out which version you have by typing this at a command prompt:
If it says
Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)
or later, you have the broken version. Previous versions should work fine.
Note that the bug stems from a broken LLVM 3.4 release and is inherited by later releases. So clang++ 3.4 and later on other operating systems will not work either (this includes Linux and likely also FreeBSD). As of C13.04 Cloudy will disable trapping FPEs when using clang++, allowing it to run Cloudy correctly even with recent versions of Xcode / clang++.
In earlier versions of Cloudy you can achieve the same effect by commenting out the call to enable_traps() in the file cpu.cpp
/* set FP environment to trap FP exceptions */ // enable_traps();
One solution is to download an older version of the command line tools from the Apple Developer web site. The late October 2013 Xcode command line tools does have a working LLVM. This is the last version that worked.
here is collection of software for high-performance computing on a Mac. This includes a downloadable version of gcc.
Subscribing to the bug may, or may not, help
We hope that the LLVM developers will fix the bug in the compiler. The problem is how the compiler handles floating point exceptions when it optimizers code. It is important that science and engineering codes handle floating point exceptions, things like division by zero, correctly. It may, or may not, help if you let them know that the LLVM bug affects you by subscribing to the bug report, posted here. It probably will not help making comments since it will appear that we are lobbying for the bug to be fixed, but subscribing to the report will indicate interest and that it affects you.
'save species' broken
The save species command can cause an abrupt termination of Cloudy execution. This occurs for at least the following platforms:
$ clang++ --version Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn) Target: x86_64-apple-darwin14.1.0 Thread model: posix $ clang++ --version Apple LLVM version 7.0.0 (clang-700.1.76) Target: x86_64-apple-darwin15.0.0 Thread model: posix
GCC is immune to this problem.
Return to CompileCode
RunCode describes how to run the code
Return to StepByStep instructions.
Return to nublado.org