Installation
Although xtensor is a header-only library, we provide standardized means to install it, with package managers or with cmake.
Besides the xtensor headers, all these methods place the cmake project
configuration file in the right location so that third-party projects can use
cmake’s find_package to locate xtensor headers.
Using the conda-forge package
A package for xtensor is available on the mamba (or conda) package manager.
mamba install -c conda-forge xtensor
Using the Debian package
A package for xtensor is available on Debian.
sudo apt-get install xtensor-dev
Using the Spack package
A package for xtensor is available on the Spack package manager.
spack install xtensor
spack load --dependencies xtensor
From source with cmake
You can also install xtensor from source with cmake. This requires that you have the xtl library installed on your system. On Unix platforms, from the source directory:
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=path_to_prefix ..
make install
On Windows platforms, from the source directory:
mkdir build
cd build
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=path_to_prefix ..
nmake
nmake install
path_to_prefix is the absolute path to the folder where cmake searches for
dependencies and installs libraries. xtensor installation from cmake assumes
this folder contains include and lib subfolders.
See the Build and configuration section for more details about cmake options.
Although not officially supported, xtensor can be installed with MinGW:
mkdir build
cd build
cmake -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=path_to_prefix ..
mingw32-make
mingw32-make install
Including xtensor in your project
The different packages of xtensor are built with cmake, so whatever the installation mode you choose, you can add xtensor to your project using cmake:
find_package(xtensor REQUIRED)
target_include_directories(your_target PUBLIC ${xtensor_INCLUDE_DIRS})
target_link_libraries(your_target PUBLIC xtensor)
Migrating from xtensor 0.25 or earlier
Starting with xtensor 0.26, headers are organized into subdirectories by
functionality. Includes such as #include <xtensor/xarray.hpp> must be
updated to #include <xtensor/containers/xarray.hpp>. The same change applies
to includes written with double quotes.
Common replacements are:
Before 0.26 |
Since 0.26 |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
For other headers, locate the filename under the installed include/xtensor
directory and use its path relative to include. Update includes in your
own headers as well as source files. Keep the compiler’s include search path
pointing to the parent of xtensor (typically <prefix>/include); adding
each new subdirectory to the search path does not replace updating the
#include directives. The CMake integration above supplies the include path.
Also check the language standard and xtl dependency when upgrading:
xtensor release |
C++ standard |
Minimum xtl version |
|---|---|---|
0.25.0 |
C++14 |
0.7.5 |
0.26.0 |
C++17 |
0.8.0 |
0.27.0 |
C++20 |
0.8.0 |
This addresses the header layout change; consult the Changelog for other API and dependency changes in the release you are upgrading to.