Building Programs on Windows, Linux, and Macintosh Systems

Ron Ghosh, June 2018, reghosh (at) gmail.com


Contents
Building programs for PC-WINDOWS
Building programs for Macintosh OS X
Building programs for Linux
Building hdf5 programs

Prebuilt Tools
Windows g77Windows gfortranMacintosh gfortranLinux gfortran
CompilerD_mingw_342.zipD_mingwgfortran.zip gfortran-4.2.3 apt-get or rpm
Librarieslibm.ziplibmgf.ziplibsOgf.zip libsLgf.zip
Utilities UnixU.zip UnixU.zip
Propprop.msi prop.msi
HDF5 Libraries and Utilities h5mgf.zip h5Ogf.zip h5Ogf.zip

Introduction
The programs in these pages are all based on Fortran code and use heavily a number of libraries and system components (the latter, esecially for screen graphics. There is a long tradition of modular programming in Fortran, hence libraries have always had great importance, compared to C programming where a single source file can offer scope for optimisation in compilation. There is a crossover point when programs reach a certain size and complexity. Standard comonents aid the compilation of calculations to run in an equivalent fashion on any of the systems above, dating from about 2005 to the current day. Interactive screen display is managed by an external display program with graphics message exchanges with the user's program. A simple guide to Fortran programming has been written with practical examples. The principal components include:

	fortran calculation code (mostly Fortran77, some Fortran 95
	(Data Fitting Library: Fitfun
	Graphics library PGPLOT*
	Graphics display program (Xwindow:pgxwin_server, Windows:GRWND.EXE"
	Utilities Library rlib
	
* Library for use only for non-profitable use - copyright T. Pearson, Caltech
" Graphics presentation on Windows(Tamaribouch)
Most of the programs described here use 32 bits, but all have equivalents running without source changes in 64 bit addressing mode.

While all the above programs run in a command shell window (Terminal or the DOS-type CMD.EXE) they can also be run from GUI interfaces (e.g. Clickfit. For PC-Windows Prop provides a more comfortable environment for running command line programs on windows, together with managing controlling features, notably environment variables, which might be a little daunting for the non-expert user..

GNU Open source compilers

Two free compilers have been used. Initially the g77, Fortran77 compiler from GNU has been used both on the linux and windows system. The last version produced was v3.4.2. Subsequently it has remained stable. It is a very fast compiler and accepts quite a range source code variants. The later gfortran compiler has been developed to include Fortran95 and newer features. There are, as a consequence, many versions which are not systematically backwards compatible. Some source code modifications were required to match the more demanding syntax of this compiler, but the sources remain compatible with the g77. The HDF library uses Fortran90 features and is incompatible with g77.

Both compilers allow routines written in C or C++ to be mixed with the Fortran. These are compiled with the gcc commmand. e.g.:

gfortran -c *.f
gcc -c *.c

The object files can be combined in a library (created with the ar command.

% ar -ruv libnewlib.a *.o

Libraries Libraries included here contain object code for 32bit programming, and basic resources (font file, screen server programs (GRWND.EXE or pgxwin_server) for pgplot graphics. This is most easily implemented by setting the environment variable PGPLOT_DIR to the library root. Other components include utilities librlib.a) and the current fitfun libraries libffn80* and libffm81*.

All the sources can been compiled for 64bit systems without change. Source code including makefiles can be obtained from reghosh (at) gmail.com. These should compile and run on any system for which the GNU-gcc suite is available (including, for example, the Rasberry-Pi with an ARM processor!)

Building programs for PC-WINDOWS

To offer similar utilities for programming windows the BSD utility programs in UnixU.zip (approx 1.4Mb) can run on PC-Windows. This enables access to commands ls, cat, rm, grep etc if the directory name is included in the default PATH. These utilities can be used with either Windows or unix file name paths back/forward-slash separators).

NOTE: most PC-Windows files can be accessed using the unix forward-slash directory name conventions in the gcc suite.

Fortran77
The MinGW distribution for GNU-gcc and g77 provides the basic compilers and libraries using v3.4.2. A zip file D_mingw_342.zip (approx 60Mb) of this distribution can be unzipped and placed in the D: disk. In the top directory D_mingw there is a batch file which sets a few environment variables. It is useful to put a windows shortcut to this batch file with the starting command:

cmd.exe /k D:\D_Mingw_342\MinGWVARS.bat

MinGWVARS.bat contains:
@echo off
ECHO Setting up MinGW environment and defining PGFLAG for building PGPLOTs 
set PGPLOT_DIR=D:\LibM
set PGPLOT_ILL_DEV_1=/GW
set PGPLOT_ILL_DEV_2=/VCPS
set PGPLOT_PPAGE=2
SET PATH=D:\D_MinGW_342\BIN;D:\UnixU\;%PATH%
set PGFLAG=%PGPLOT_DIR%\libpggw520.a  -mconsole -mwindows

a typical compile and link command is:
g77 -o gtst gtst.f inread.f gauss.f libffn74.a d:/libM/libpgplot.a -mconsole -mwindows
which may be shortened using the environment values here to
g77 -o gtst f inread.f gauss.f %PGPLOT_DIR%libffn74.a %PGFLAG%
to launch the command window with the environment set. If the file is unzipped to an alternative directory the PATH in this batch file should be edited.

Prebuilt Libraries

These contain the fitting routines (fitfun, fitfun_m, PGplot graphics and utilities (librlib.a)

 libm.zip  (approx 8.5Mb)

gfortran
The MinGW distribution for GNU-gcc and gfortran provides the basic compilers and libraries using v4.5.0. A zip file D_mingwgfortran.zip (approx 23Mb) of this distribution can be unzipped and placed in the D: disk. In the top directory gfortran there is a batch file which sets a few environment variables. It is useful to put a windows shortcut to this batch file with the starting command:

cmd.exe /k D:\Mingw\MinGWVARS.bat

MinGWVARS.bat contains:
@echo off
ECHO Setting up MinGW environment and defining PGFLAG for building PGPLOTs 
set PGPLOT_DIR=D:\libmgf
set PGPLOT_ILL_DEV_1=/GW
set PGPLOT_ILL_DEV_2=/VCPS
set PGPLOT_PPAGE=2
SET PATH=D:\gfortran\bin;D:\UnixU\;%PATH%
set PGFLAG=%PGPLOT_DIR%\libpggw520.a  -mconsole -mwindows

a typical compile and link command is:
gfortran -o gtst gtst.f inread.f gauss.f libffn74.a d:/libgf/libpgplot.a -mconsole -mwindows
which may be shortened using the environment values to
gfortran -o gtst f inread.f gauss.f %PGPLOT_DIR%libffn74.a %PGFLAG%

to launch the command window with the environment set. If the file is unzipped to an alternative directory the PATH in this batch file should be edited.

Prebuilt Libraries

These contain the fitting routines (fitfun, fitfun_m, PGplot graphics and utilities (librlib.a)

 libmgf.zip  (approx 8.5Mb)

Building programs for Macintosh OS X gfortran

Because X-window is used for screen graphics it is necessary to obtain and install the Xcode package from the Applestore repository (Software Update). This contains the system libraries and the application to manage X-window. With XCode 4 or better you will need to download the command-line tools as an additional step. You will find the option to download the command-line tools in XCode's Preferences. On 10.9 Mavericks or higher, you can get the command-line tools by simply typing xcode-select --install. The disk image of the gfortran package version 4.2.3 (approx 28Mb) can be installed. Versions of gfortran for Mac-OSX can be found at https://github.com/fxcoudert/gfortran-for-macOS/releases

On later systems the system routine crt1.o, necessary for linking programs, has been
omitted from the system library (/usr/lib).  It is necessary to copy it from the Xcode
package to /usr/lib
% ls -l /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib/crt*
or
% sudo find / -name "ctr1.*" -print

Prebuilt Libraries

These contain the fitting routines (fitfun, fitfun_m, PGplot graphics and utilities (librlib.a). The first contains 32 bit code generated by gfortran-4.2.3. The second contains 64 bit code generated by gfortran-8.2.0 (Mojave)

 libsOgf32.zip  (approx 8MB)
 libsOgf.zip  (approx 19MB)


Building programs for Linux gfortran

Most systems can locate and install gfortran from their program database. It may also be necessary to install X11-dev or similar packages toadd the X11 libraries and build components to enable linking.

Prebuilt 32-bit Libraries

These contain the fitting routines (fitfun, fitfun_m, PGplot graphics and utilities (librlib.a)

 libsLgf.zip  (approx 8Mb)
Building programs for treating HDF5 data

The following zip files contain sources of utilities, executables, makefiles and libraries to build them for the three systems Linux,OS X, and Windows with the gfortran Fortran90 compilers.