Building MAVSDK on Linux ​
This guide explains how to build MAVSDK from source on Linux systems.
Requirements ​
The build requirements are git, cmake, and a C++ compiler (GCC or Clang), and python.
Ubuntu ​
sudo apt-get update
sudo apt-get install build-essential cmake git python3 python3-pipFedora ​
sudo dnf update
sudo dnf groupinstall "Development Tools" "Development Libraries"
sudo dnf install cmake gitGetting the Source ​
Download the source using git:
git clone https://github.com/mavlink/MAVSDK.git
cd MAVSDK
git submodule update --init --recursiveBuilding the MAVSDK library on Linux ​
Debug Build ​
For development, use the debug build:
cmake -DCMAKE_BUILD_TYPE=Debug -Bbuild -S.
cmake --build build -j8Release Build ​
For production use, build with optimizations enabled:
cmake -DCMAKE_BUILD_TYPE=Release -Bbuild -S.
cmake --build build -j8Installation ​
System-wide Installation ​
To install system-wide in /usr/local:
sudo cmake --build build --target install
sudo ldconfig # Update linker cacheLocal Installation ​
To install to a custom location, e.g. install
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install -Bbuild -S.
cmake --build build --target installBuild mavsdk_server binary on Linux ​
Language wrappers for MAVSDK other than C++ connect to the MAVSDK C++ core using gRPC. This gRPC server around the MAVSDK C++ library is called mavsdk_server (in the past it was referred to as the backend).
For more information about the architecture, also see how the auto-generation works.
In order to include the mavsdk_server in the build, add -DBUILD_MAVSDK_SERVER=ON:
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_MAVSDK_SERVER=ON -Bbuild -S.
cmake --build build -j8Build Options ​
During the configure step you can set various flags using -DFLAG=Value:
CMAKE_BUILD_TYPE: Choose betweenDebug,Release, orRelWithDebInfo(optimizations and debug symbols)CMAKE_INSTALL_PREFIX: Specify directory to install library artifactsBUILD_SHARED_LIBS: Set toONfor dynamic libraries (.so),OFFfor static libraries (.a)SUPERBUILD: Set toOFFto use system dependencies instead of third party dependencies (see Building without Superbuild)CMAKE_PREFIX_PATH: Set path where dependencies can be found ifSUPERBUILDisOFFBUILD_MAVSDK_SERVER: Set toONto build mavsdk_serverBUILD_WITHOUT_CURL: Set toONto build without CURL supportASAN: Set toONto enable address sanitizerUBSAN: Set toONto enable undefined behavior sanitizerLSAN: Set toONto enable leak sanitizerWERROR: Set toONto treat warnings as errors
MAVLink Configuration ​
MAVSDK supports configuring the MAVLink dialect and repository:
MAVLINK_DIALECT: MAVLink dialect to use (default:ardupilotmega)MAVLINK_XML_PATH: Path to local MAVLink XML definition files. If not set, definitions are fetched automatically.MAVLINK_URL: URL for the MAVLink repository (default:https://github.com/mavlink/mavlink)MAVLINK_HASH: Git commit hash to use from the MAVLink repository
Note: You can also load custom MAVLink message definitions at runtime using the MavlinkDirect plugin, without needing to rebuild MAVSDK.
Examples:
# Build with development dialect
cmake -DCMAKE_BUILD_TYPE=Debug -DMAVLINK_DIALECT=development -Bbuild -S.
# Use a custom MAVLink repository fork
cmake -DCMAKE_BUILD_TYPE=Debug \
-DMAVLINK_URL=https://github.com/yourfork/mavlink \
-DMAVLINK_HASH=abc123def456 \
-Bbuild -S.
# Use local MAVLink XML files
cmake -DCMAKE_BUILD_TYPE=Debug \
-DMAVLINK_XML_PATH=/path/to/mavlink/message_definitions/v1.0 \
-Bbuild -S.Building without Superbuild ​
By default, MAVSDK uses a "superbuild" that automatically downloads and builds all required dependencies. If you prefer to provide dependencies yourself (e.g., from system packages or custom builds), you can disable this with SUPERBUILD=OFF.
A script is provided that demonstrates how to build all dependencies and MAVSDK:
./tools/build-with-system-deps.shThis script:
- Clones and builds the required dependencies (MAVLink, libevents, PicoSHA2, libmav) into a local
deps/directory - Installs them to
deps-install/ - Builds MAVSDK with
SUPERBUILD=OFFusing these dependencies
Prerequisites (install before running the script):
sudo apt install build-essential cmake git python3 python3-pip \
liblzma-dev libtinyxml2-dev libjsoncpp-dev \
libcurl4-openssl-dev libssl-devTroubleshooting ​
Git Submodules Out of Date ​
If you encounter build issues, try updating the submodules:
git submodule update --recursiveUndefined References ​
If you get undefined reference errors after installation, update the linker cache:
sudo ldconfigAnd try a clean build by wiping the build directory:
rm -r build
