Skip to content
Peter Spackman edited this page Aug 16, 2016 · 3 revisions

For distribution, often we would wish to make a static build of tonto, hart (or other binaries).

Standard linux binary

Normally, it’s just a matter of using the RELEASE-STATIC build in cmake as follows:

cmake -DCMAKE_BUILD_TYPE=RELEASE_STATIC

The resulting binary will be a static, redistributable binary.

Cross compiling for windows

The easiest way to create a binary for windows is to cross-compile using mingw-w64.

These can be install on ubuntu as follows: sudo apt-get install mingw-w64-i686-dev mingw-w64-x86-64-dev Similar instructions should work on Fedora/RHEL/CentOS.

Toolchain files

Basically we just wish to tell cmake to use the mingw-w64 compilers and linkers, and one way to do this is with a ‘toolchain’ file (which is just a cmake script).

An example file may be found here

Once we have a toolchain file, simply build the binary with:

cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain_file.cmake ..
make -j4

The result will be windows binaries, (32- or 64-bit depending on whether you used i686 or x86_64 toolchains).

OS X

Building a static binary on OS X is technically not possible, but we can still get something redistributable.

My advice is simply don’t do this unless you really have to. It’s an annoying solution to avoid bundling dynamic libraries. Basically the goal is to get as much of it to be static as we can.

This would be a lot easier if gfortran had a -static-libquadmath flag, but sadly that’s not the case at this time, so we have to do an awful workaround.

Basically just run the build as normal on os x:

cmake -DCMAKE_BUILD_TYPE=RELEASE ..

After this is completed, locate where your gcc libraries are (usually this is /usr/local/lib/gcc/6/ or whatever version number of gcc you’re using).

We then have to hide the dynamic libquadmath as it will be linked preferentially even if we specify the static library manually.

GCC_LIBS=/usr/local/lib/gcc/6
mkdir tmp/hide-libs
mv $GCC_LIBS/libquadmath*.dylib tmp/hide-libs

After this we manually link the binary:

gfortran -o tonto-static run_molecule.F90 libtonto.a $GCC_LIBS/libquadmath.a -static-libgcc -static-libgfortran -framework Accelarate

You can check what is still dynamically linked as follows:

otool -L tonto-static

This should print something like the following:

/path/to/tonto:
	/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)

Since both of these are available on OS X by default, it should work (though might miss some older systems).

Don’t forget to return the libquadmath dynamic libraries back to where they belong:

mv tmp/hide-libs/*.dylib $GCC_LIBS