Compiling C96
Home Up C94.00 Other versions Revision history The future etcetera Acknowledgements Contacts, Mailing list Links Site map, search




Compile the code with an ANSI C compiler

Instructions for various compilers are given below.  In each case, from the command prompt, cd into the source directory and compile everything using the wildcards indicated below. 

Compile options should be set so that the machine throws an exception on division by zero or overflow.  Underflow is inevitable and should not be trapped.  The examples below show how this can be done on various machines. This version has code in setfpenv.c that will set the proper floating point environment for nearly all systems.  Not all distributions of gcc include fpu_control.h (the Cygwin distribution that I use does not) so this piece of code may create problems on some systems.  

A note on aggressive optimization:  If you try to use your compiler's highest optimization levels you will probably just find compiler bugs, at least when compiling a code as large as Cloudy.  Do a debug compile first, check that all went well by running the test suite (described here), and then try the tests with the optimized code.  When that fails you will need to do a binary search to find the routine the compiler could not handle, by compiling half the code in debug, and half in optimized mode, eventually tracing down which files could not be compiled with optimization.  The compiler vendor may repair the bug if you can isolate it down to a few lines of code.  My experience is that aggressive optimization only gains another 5 to 15 percent speedup and is not worth the bother.

makefiles:  The compiler I use does not use makefiles, so I can't provide one.  If someone is interesting in creating a makefile and sending it to me, I will post it on this web site.

A note on routine CrashDo:  This routine contains logic designed to cause the code to crash.  It is the implementation of the crash command.  Good compilers will detect dangerous code in this routine and create warnings.  This is by design, and so OK.

The remainder of this page gives advice on compiling the code on various platforms.


Make sure that you do not have version gcc 2.96.  This version of gcc is broken, will not work, and is the version included in many Linux distributions.   To find out which version of gcc you have type "gcc -v".  If you have version 2.96 then you probably also have kgcc, an older version of gcc that is capable of compiling the Linux kernel (version 2.96 can't even do that).  Use kgcc in this case.  (Versions of Cloudy downloaded after 2002 Feb 27 include code to check for gcc 2.96, and will refuse to execute if that compiler is used.)  3.0x versions of gcc will not compile the code with aggressive optimization but we have obtained excellent results with version 3.10 of gcc.  Use kgcc, 2.95, or 3.10 or later.

Versions before 2.1 of the gcc library glibc have problems with floating point precision on Intel processors.  Make sure that you have version 2.1 or later if you plan to work on an Intel box.  

There is a major bug in some versions of the math library that comes with gcc on Dec Alphas.  If you are running Linux on an Alpha please read this

Peter van Hoof found a way to disable gradual underflows when using gcc on ultrasparcs - this results in a major speedup.  See the comments around the macro "HAVE_SUNMATH" in setfpenv.c.

The compiler warning "CrashDo:  ar1 might be used uninitialized in this function" is expected.

debug compile
gcc -ansi -Wall -g -c -O1 *.c
gcc -o cloudy.exe *.o -lm

optimized compile
gcc -ansi -c -O3 -ffast-math -Wall *.c
gcc -ffast-math -o cloudy.exe *.o -lm
(Note - there is no space after the ffast).

In all four command lines shown above the "o" or "O" is the letter "oh" not the number zero.

The code is tested on this platform on pretty regular intervals.

Dec/Compac/??? Alpha

This concerns the native C compiler on Tru64.  See the gcc section above if you are using gcc.  On a Linux alpha cc is aliased to gcc, and the native compiler is called ccc.

debug compile
cc -g -std1 -trapuv -check_bounds -c *.c
cc -o cloudy.exe *.o -lm

These options will trap uninitialized variables, array bounds overruns, and floating point exceptions. 

optimized compile:
cc -std1 -c -fast *.c
cc -o cloudy.exe *.o -lm

The code is tested on this platform on pretty regular intervals.

Sun Solaris

debug compile:
cc -Xc -lm -g -c *.c
cc -g -o cloudy.exe *.o -lm

optimized compile:
cc -Xc -lm -fast -c *.c
cc -fast -o cloudy.exe *.o -lm

Peter van Hoof writes
The -Xc option tells the compiler to expect "maximally conformant ANSI C code".   Beware that there are actually two versions of cc on Solaris machines. One resides in /usr/ucb/cc, and is a wrapper to make the C compiler BSD compatible.   This version uses a non-standard sprintf function that returns a pointer to the string buffer instead of an int containing the number of bytes written. If you are using this version then prtcomment.c will fail to compile. The code will compile correctly with the regular version of the C compiler, usually located in /opt/SUNWspro/bin/cc (the location may vary, contact your system manager for further information). You can find out which version you are using by typing "which cc". If this returns "/usr/ucb/cc", change your path to point to /opt/SUNWspro/bin/cc, or use gcc."

The warning  "/usr/include/ieeefp.h", line 123: warning: dubious reference to enum typedef: fp_rnd" appears to be benign.

Optimized compile with gcc on Sun

gcc -ansi -c -mcpu=ultrasparc -O3 -ffast-math -Wall -DSTD_ASSERT *.c
gcc -ffast-math *.o -lm

The code is tested on this platform on irregular intervals.


debug compile:
cc -ansi -c -w -g -DEBUG:trap_uninitialized *.c
cc -IPA -o cloudy.exe *.o -lm

To include array bounds checking, change the DEBUG statement to the following:

optimized compile:
cc -ansi -c -Ofast -w -TARG:exc_max=OZV -TARG:exc_min=OZV *.c
cc -o cloudy.exe -IPA *.o -lm

I do not have access to an SGI machine and so the code has not been tested on this platform in several years.  Good luck.  Please let me know what happens!


debug compile:
cc -c -g -Aa +e +z *.c
cc +FPZO -o cloudy.exe *.o -lm

optimized compile
cc -Aa -O -c +z +e *.c
cc +FPZO -o cloudy.exe *.o -lm

The code has been very well tested on this platform.  The University of Kentucky HP cluster is described here.

MS Visual Studio 6

Create a new "win32 console application".  Add all the source files to the project.  Select the "disable language extensions" option under projects\settings\c++\customize tab.  I also set the "warning level" under projects\settings\c++\general to 4 but this is not necessary.  With this IDE the debug and optimized versions are referred to as "debug" and "release".

MS Visual Studio Dot Net

Create a new new project from the file/new project option. In "Project Types" select "Visual C++ Projects".   Under "templates" select "Win32 Project" and enter a name for the project.  Click OK  Next the Win32 Application Wizard opens.  Click "application settings".  Select "console application" and "empty project" then click on "finish".  Now add all the source and header files to the project with the "project/add existing files" option..  I also set the "warning level" under projects\settings\c++\general to 4 but this is not necessary.  With this IDE the debug and optimized versions are referred to as "debug" and "release".

The code is developed on this platform.

MAC Darwin

I have never used this system, but Donglai Gong has.  He writes "for MacOS X users, they'll first need to download Apple Developer's Tools (free with registration from Apple's developer website) which includes gcc. When you get there then go to the Download section and follow the link to Mac OS X, you'll see the developer tools being listed.  I should also say that Apple's current cc (as of OS X 10.2) is basically gcc 3.1.   All Macs shipping with Mac OS X 10.2 supposedly have the developer tools included on one of the install CD's, although it's not installed by default."

Compiling cloudy on MacOS X 10.2/Darwin 6.0.1

optimized compile:
 cc -ansi -c -Wall -no-cpp-precomp -O3 -ffast-math *.c
cc -o cloudy *.o -lm

Many thanks to Donglai Gong for testing the code on this platform.

Next step: how to execute the code. 

Hit Counter
Last changed 04/05/03.
Return to the Cloudy Home Page.
Copyright 1978-2003 Gary J. Ferland