Skip to content

Installation instructions

Tom Schoonjans edited this page Aug 29, 2024 · 45 revisions

Downloading the source

You can obtain the latest and historical releases of the xraylib source code from the Releases section.

After downloading the tarball, unpack and compile the source code using the following commands:

unxz xraylib-version.tar.xz

tar xvf xraylib-version.tar

cd xraylib-version

I would strongly recommend NOT to download the Source code tarballs that are created by Github, as these do not come with the configure file that is used when building with the GNU Autotools scripts. It is still possible though to compile the software based on this package, if you run autoreconf -i after unpacking the tarball, and then following the rest of the steps outlined in the installation section. This requires a complete installation of the GNU build tools Autoconf, Automake and Libtool (at least version 2.0!).

Compilation from source with meson

Meson is a modern and fast build system with excellent support for all major platforms and compilers. xraylib 4.1.0 introduced support for this build system as an alternative to the older GNU Autotools based configure script and Makefiles. Since Meson does not need a bash shell to run, it is now possible to build using the Visual Studio compiler suite.

Before proceding, you will need to install a sufficiently recent version of meson (>= 0.60.0) on your machine. Detailed instructions can be found here. Since meson is written in Python, you will also need to install a suitable Python 3 interpreter.

After unpacking the xraylib tarball, run the following commands to build xraylib:

meson setup builddir --buildtype=release --prefix=<path-to-installation-dir>

ninja -C builddir

ninja -C builddir test

ninja -C builddir install

The last command may need to be executed as an administrator or root, depending on the chosen installation prefix.

Several flags can be added to the meson command to tweak its behaviour such as which Python interpreter to use etc.

To see the list of flags run:

meson configure

Note that meson build supports only building the core C library, as well as the Fortran and Python bindings. If you need to build any of the other language bindings, you must use the GNU Autotools configure script!

Compilation from source with GNU Autotools

After unpacking, you will first need to generate the configure script and associated files (this may require installing autoconf, automake and libtool first):

autoreconf -fi

Next, run the configure script:

./configure

make

Optional, but recommended is to check if the compilation went well:

make check

Depending on the requested install location, it may be necessary to perform the installation as a user with administrative privileges

make install

configure and make will try to build as many bindings as possible (except for the PHP and Pascal bindings, which will only be built if the --enable-php and/or --enable-pascal options are passed). If some of these would be considered as redundant, it is possible to disable their compilation using -—disable-binding options to configure. See ./configure -—help for a list of all options.

The default behavior is for the libraries and the bindings to be installed in subdirectories of --prefix=<your_installation_root> (default is /usr/local). This could cause the user to be forced to define language specific environment variables before the bindings become usable. This problem can be circumvented by forcing the bindings to be installed in the default locations as set when the specific interpreter (Perl, Python etc) was built. For this purpose, the --enable-perl-integration, --enable-python-integration, --enable-ruby-integration and --enable-php-integration options were added to the configure script. This is considered an advanced feature and is not recommended for standard installations.

More information can be found in the README and INSTALL files that are included in the package.

macOS

The recommended way to install xraylib on macOS is through Homebrew. In a terminal type in the following command:

brew install tschoonj/tap/xraylib

Most bindings are supported, as can be seen when invoking the info option:

brew info tschoonj/tap/xraylib

We have also released a universal framework (32/64-bit Intel) for inclusion in Xcode projects. A zipfile containing the framework can be found in the Releases section. After unpacking, either drag it straight into your Xcode project or copy it into /Library/Frameworks.

Windows SDK

We have created an xraylib SDK (64-bit) for the Windows operating system. To install, download the xraylib-{version}-win64.exe file from the Releases repository and double-click to activate the installation wizard. Depending on the selected options, this will install the headers, examples, static libraries and the dynamic-link library (dll) into the appropriate folders. The SDK has been verified to work with several compilers: mingw32, Microsoft Visual C++, Intel C++.

The README.TXT file in the Lib subdirectory of the xraylib SDK explains the steps we used to create this package, as well as some advice on how to use it.

Java JAR with OSGi support

xraylib release 3.2.0 introduces a completely rewritten implementation of the Java bindings. Unlike the previously provided SWIG generated JNI bindings, this new version is rewritten in pure Java and is not linked to the xraylib shared library. The jar comes with an OSGi manifest and can therefore easily be integrated into software projects that support the OSGi standard (e.g. Eclipse).

The jars (bin, sources and javadoc) are distributed via JFrog and Maven Central, where instructions can be found to easily include xraylib in your Java projects. The xraylib java implementation has a single dependency: Apache Commons Math 3 for the use of its Complex class, which is used by the diffraction API.

Anaconda

Anaconda is a Python distribution that is particularly popular within the scientific community due to its support for packages that cannot (easily) be made pip-compatible due to the presence of C, C++ and Fortran code.

Though several people have uploaded xraylib packages to their own channels, we are only supporting those provided by conda-forge for the Linux, macOS and Windows operating systems. Users of Windows are especially encouraged to use these packages as the SDK no longer ships the xraylib Python modules, thereby turning conda-forge into the exclusive distribution channel for xraylib's Python modules on Windows.

In order to install the packages, execute the following command in your shell:

conda install -c conda-forge xraylib

PyPI

We are now also producing xraylib Python wheels for all major architectures and supported versions of Python. You can install these easily with:

pip install xraylib