This section explains how to build and install the MAVSDK C++ library from source for all our target platforms.
Note that there are separate instructions to build the mavsdk_server.
This section explains how to build the library along with its unit and integration tests.
The build requirements are git, cmake, and a compiler such as GCC, Clang, or MSVC.
sudo apt-get update sudo apt-get install build-essential cmake git
sudo dnf update sudo dnf groupinstall "Development Tools" "Development Libraries" sudo dnf install cmake git
sudo pacman -Sy base-devel cmake git
First install XCode Command line tools:
And Homebrew (for cmake).
Once you have installed brew, you can install
brew in the terminal:
brew install cmake
To build the library in Windows, you need:
- Build Tools for Visual Studio 2019: Download and install (only the "Visual C+ Build Tools" are needed from installer).
- cmake: Download the installer and run it. Make sure to tick "add to PATH" during the installation.
- git or any other tool to work with git.
Note: Building using Cygwin or MingW is not supported.
Download the source using git:
git clone https://github.com/mavlink/MAVSDK.git
Make sure to get all the submodules as well:
git submodule update --init --recursive
To build the MAVSDK C++ Library for development, use the debug build.
Configure first, then build:
cmake -DCMAKE_BUILD_TYPE=Debug -Bbuild/default -H. cmake --build build/default -j8
Once you ship software, make sure to use the release build with optimizations turned on:
cmake -Bbuild/default -DCMAKE_BUILD_TYPE=Release -H. cmake --build build/default -j8
cmake -Bbuild/default -H. -DCMAKE_BUILD_TYPE=Release cmake --build build/default -j8 --config Release
Note: It is not usual to use CMAKE_BUILD_TYPE on Windows (with MSVC), however, our build requires it for the dependencies which are built at configure time.
Installing builds the SDK and copies the libraries and header files into a "public" location so that they can be referenced by C++ applications (see Building C++ Apps).
By default (when
CMAKE_INSTALL_PREFIX is not set, cmake tries to install system-wide. For Linux/macOS that's
/usr/local, for Windows it is somewhere in
To install system-wide the command needs to be run with sudo on Linux/macOS:
sudo cmake --build build/default --target install
or run in a command prompt with admin privileges on Windows, or using
runas cmake --build build/default --target install
Make sure to prevent conflicts between libraries installed in your system. The mavsdk library installed via a .deb or .rpm file will be installed in
/usr/while the built library will be installed in
/usr/local. It's recommended to only have one installed at any time to prevent conflicts.
The install path can be set in the configure call using
For example, to install into the
MAVSDK/install/ folder you woul set the
CMAKE_INSTALL_PREFIX variable to specify a path relative to the folder from which you call
cmake (or an absolute path).
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install -Bbuild/default -H. cmake --build build/default --target install
If you already have run cmake without setting
CMAKE_INSTALL_PREFIX, you may need to clean the build first:
rm -rf build/default
During the configure step, there are various flags that an be set using
CMAKE_BUILD_TYPE: as documented above, to chose between
CMAKE_INSTALL_PREFIX: as documented above, to specify directory to install library artefacts.
BUILD_SHARED_LIBS: set to
ONto build dynamic libraries (such as .so on Linux, .dylib on macOS, .dll on Windows). Set to
OFFto build static libraries (such as .a on Linux and macOS, .lib on Windows).
SUPERBUILD: set to
OFFto use system dependencies instead of dependencies downloaded and built using cmake.
CMAKE_PREFIX_PATH: can be used to set the path where the dependencies can be found if
SUPERBUILDis set to
BUILD_MAVSDK_SERVER: set to
ONto build mavsdk_server, see instruction to build mavsdk_server.
ASAN: set to
ONto enable address sanitizer.
UBSAN: set to
ONto enable undefined behavior sanitizer.
LSAN: set to
ONto enable leak sanitizer.
WERROR: set to
ONto error on warnings, mostly used for CI.
Some common build issues can be resolved by updating submodules and cleaning the distribution:
cd MAVSDK git submodule update --recursive rm -rf build
Then attempt to build again.
We only try to support building using MSVC, MingW is not working, mostly because the defines/flags for it are missing.
If you only just built the library and installed it system-wide may also need to update the linker cache.
On Linux this is done with