Compiling BA3 for Windows
I am not a Windows user, however plenty of BayesAss users are. For this reason I keep a recent version of Windows on a dual-boot linux notebook where I can compile and test BA3 on the Windows OS. Here I outline the procedure that I use to compile BA3 for Windows using a port of the gcc compiler to Windows known as MinGW. MinGW compiles the BA3 program to create an executable that runs under either a 32 or 64-bit Windows operating system. These notes are very brief and intended mostly for my use so that I can remember how to compile the program under Windows as I do this fairly infrequently and tend to forget. However, even a user without prior programming experience should be able to follow the example code and compile the program from source themselves.
Why not cross-compile?
Personally, I would prefer to never have to use Windows. For one thing, every time I start up the Windows OS it is normally 6 months to a year behind on updates and I spend hours downloading and installing gigabytes of security patches and other updates. Ugh. The MinGW is available for linux and in principle one can cross-compile program for Windows directly in linux and then test the binaries using the Wine windows emulator. This is relatively easy when there are no external libraries – a simple “hello world!” program for example. However, I encountered difficulties trying to cross-compile BA3 because it uses the Gnu Scientific Library (gsl). A Windows binary of this library has to be created first and then linked to the BA3 program when it is compiled, something I could not manage so I gave up and moved on to the procedure described here which is to install the MinGW compiler suite on the Windows machine and then compile the Windows executables. If you have managed to cross-compile BA3 under linux I would love to hear the details – email me.
Preparing to compiling BA3
The first step in this procedure is to install the MinGW compiler package. There are currently two separate distributions of MinGW. The original MinGW project (circa 2005) which is a bit stale now, and the MinGW-W64 project that was forked from MinGW in 2007. Here we will use a program MSYS2 that implements a small unix shell for Windows and includes a package manager pacman that will allow us to install the MinGW-W64 compilers and also the libraries needed for compiling BA3. There is a Windows binary of the gsl library available through pacman which eliminates the need for compiling gsl ourselves. Download MSYS2 from www.msys2.org. Be sure to download the correct executable “x86_64” for a modern 64-bit or “i686” for an older 32-bit Windows OS.
After installing MSYS2 run the program and type the following command at the shell prompt
then follow the prompts to update all the installed packages. Now we need to install three additional packages to compile BA3
pacman -S mingw64/mingw-w64-x86_64-gsl mingw64/mingw-w64-x86_64-gcc msys/make
I have installed the 64-bit binaries. If you are compiling for 32-bit Windows replace x86_64 with i686. Exit and restart the MSYS program. We are now ready to compile!
Download the latest source code for BA3 from github.com/brannala/BA3. Place the source code in a subdirectory of your home directory, for example C:\Users\Bruce\BA3. Open MSYS and move to that directory
Now edit the file named Makefile using a text editor. I prefer the command line text editor emacs which can be installed in MSYS2 with the commands
pacman -S mingw64/mingw-w64-x86_64-emacs
To use emacs to edit the Makefile type
Edit the contents of the Makefile to be:
INCLUDE = -Iinclude CFLAGS = -O3 LDLIBS = -lgsl CC = g++ all: $(CC) $(CFLAGS) src/main.cpp $(INCLUDE) $(LDLIBS) -o BA3_x64
Note that the space below all: must be a single tab. Save your changes to the Makefile and type make. That should cause the program to compile and produce a Windows executable file named BA3_x64.exe.