Windows/MSYS2: Building a Bmad Distribution

Developed by: Thomas Gläßle <t_glaessle "AT" gmx.de>

Preparing the build environment

We describe building with MSYS2: Download and install MSYS2 from https://msys2.github.io/. Choose the installer for the system you are building on (x86_64 for 64bit, i686 for 32bit). You will be able to build for both 32bit/64bit in any case.

Update MSYS2 according to the instructions on the download page or here.

Save and execute msys2.reg to be able to conveniently start MSYS from explorer in any folder by right clicking.

Now, start an MSYS2 shell (via explorer context menu or C:\msys64\mingw64.exe or C:\msys64\mingw32.exe) according to which target architecture you are going to build. Note, inside the shell $MSYSTEM_CARCH should now either x86_64 for 64bit or i686 for 32bit.

Next, install dependencies
pacman -S base-devel bc
pacman -S mingw-w64-$MSYSTEM_CARCH-{gcc,gcc-fortran,readline,pcre,cmake,qt4}

Troubleshooting: If a download fails with "operation too slow", try installing wget (pacman -S wget) and uncommenting the following line in /etc/pacman.conf:
!XferCommand =/usr/bin/wget --passive-ftp -c -O %o %u

Make sure that gmake is available:
ln -s /usr/bin/{,g}make.exe

Building Bmad

Start with a clean folder. Download and extract the latest distribution bmad_dist_YYYY_MMDD.tgz and open an MSYS2 shell (32bit/64bit) in the bmad_dist_YYYY_MMDD directory.

In the util/dist_prefs file, set the following (unless there is a good reason not to):


This can conveniently be done by executing the command
patch -p0 < util/dist_prefs_for_windows.diff

Proceed to build the Bmad distribution the same as in bash as on other operating systems.

source ./util/dist_source_me

Linking from VS to MinGW generated libraries

It's possible to link in Visual Studios to the static libraries (.a files) generated by the MSYS/MinGW builds. Just add the relevant files to the project's additional link libraries and the corresponding pathes as input pathes. Thisworks on both x64 and x86. The only related issue was that I had to change the setting in Project -> Properties -> Linker -> Advanced -> Image has Safe Exception Handlers to No (/SAFESEH:NO).

For more information regarding potential problems, see http://stackoverflow.com/questions/2096519/from-mingw-static-library-a-to-visual-studio-static-library-lib/2139061#2139061.

Windows 10/Ubuntu: Building a Bmad Distribution

The following scripts install a Bmad Distribution with Ubuntu and Windows 10. This script references the bmad_dist_2020_0114 distribution. To use, substitute the name of the current distribution. There are other changes that you might want to make. For example, where the Distribution is installed.

Scripts developed by: Yuki ABE (2020/01/17)
Modifified by: David Sagan

# Environment setup.
# Written by Yuki ABE(2020/01/17)

# make directory for BMAD
cd ~
mkdir BMAD

# we are in "~/BMAD" now
sudo wget https://www.classe.cornell.edu/~cesrulib/downloads/tarballs/bmad_dist_2020_0114.tgz
sudo tar xzf bmad_dist_2020_0114.tgz
echo export DIST_BASE_DIR=${BMAD_DIST}/bmad_dist_2020_0114 >> ~/.bashrc
echo 'source ${DIST_BASE_DIR}/util/dist_source_me' >> ~/.bashrc
echo ulimit -S -c 0 >> ~/.bashrc
echo ulimit -S -s 10240 >> ~/.bashrc
echo ulimit -S -d 25165824 >> ~/.bashrc
source ~/.bashrc


# Package install
# Written by Yuki ABE(2020/01/17)

sudo apt-get update
gcc --version
g++ --version
gfortran --version

# prepare compilers(C,C++,fortran)
sudo apt-get -y install gcc
sudo apt-get -y install g++
sudo apt-get -y install gfortran

# instal cmake
sudo apt-get -y install cmake
sudo apt-get -y install gmake
sudo apt-get -y install automake
sudo apt-get -y install autoconf
sudo apt-get -y install libtool
sudo apt-get -y install m4

# ??
sudo apt-get -y install Tao
sudo apt-get -y install readline
sudo apt-get -y install ncurses
sudo apt-get -y install termcap
sudo apt-get -y install libX11
sudo apt-get -y install yum
yum install readline-devel

# install pgplot
sudo apt-get -y install pgplot5
sudo ln -s /usr/bin/make /usr/bin/gmake
sudo apt-get -y install libtool-bin
sudo apt-get -y install libncurses-dev
sudo apt-get -y install libreadline-dev
sudo apt-get -y install libx11-dev
sudo apt-get -y install libxt-dev

# they are also needed
sudo apt-get install libreadline6-dev
sudo apt-get install libreadline-gplv2-dev
sudo apt-get -y install x11-apps
sudo apt-get -y libsm-dev

Modify the settings in util/dist_prefs if desired before running the next script.


# Written by Yuki ABE (2020/01/17)
# compiling BMAD


#util/dist_clean # Use this to remove compiled files and restart from scratch
util/dist_build_debug   # Only needed if you are going to debug code.
Topic revision: r21 - 24 Jan 2020, DavidSagan

  • ACC/ACL Web

  • CLASSE Computing Info

Create personal sidebar

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding CLASSE Wiki? Send feedback