Can't link C++ offboard control code. Utterly stumped

Hey gang,

Working on some C++ code to do things like send in a new mission, grab vehicle telemetry to feed into some other systems, etc.

Our code exactly follows the most recent version of the Offboard examples (such as MAVSDK/examples/offboard/offboard.cpp at d17def1dae469f637bc70972f474df05f0abe31e · mavlink/MAVSDK · GitHub) in terms of what we’re importing, and as far as our CMakeLists.txt. Note, this is for incorporation into a ROS-melodic (yes I know, it’s old, there’s reasons for us using it), but we’re using MavSDK to do the interfacing to the PX4. As such we’ve tried both the pre-built 1.4.16 libmavsdk-dev_1.4.16_ubuntu18.04_amd64.deb as well as built MavSDK from source, but running into the same issues whenever we try either.

In our CMakeLists.txt we have:

find_package(MAVSDK REQUIRED)


We have our import statements in our .cpp as:

#include <mavsdk/mavsdk.h>
#include <mavsdk/system.h>
#include <mavsdk/plugins/action/action.h>
#include <mavsdk/plugins/offboard/offboard.h>
#include <mavsdk/plugins/telemetry/telemetry.h>
#include <mavsdk/plugins/mission/mission.h>

Every time I try to build, I’m getting a linker error on the Telemetry, Mission, Offboard and Action classes:

undefined reference to ‘mavsdk::Mission::Mission(mavsdk::Mission const&)’

related to these lines of code:

mavsdk::Telemetry telemetry{system_ptr};
telemetry_ptr = std::make_shared<mavsdk::Telemetry>(telemetry);
mavsdk::Action action{system_ptr};
action_ptr = std::make_shared<mavsdk::Action>(action);
mavsdk::Offboard offboard{system_ptr};
offboard_ptr = std::make_shared<mavsdk::Offboard>(offboard);
mavsdk::Mission mission {system_ptr};
mission_ptr = std::make_shared<mavsdk::Mission>(mission);

(Note, this is a bit different than how it’s done in the current offboard.cpp example, as when we tried to do it the way shown in the example we got a no constructor match error, and it says that passing in the system itself is deprecated now and we should pass the shared ptr instead.) So wondering if the example code is even correct anymore???

We’re doing this all inside docker containers, but I took out building of the module that’s giving us problems, built the container, started it and went into it via bash, and looking around I can see both the headers and the .so lib inside their respective /usr directory locations, so the .deb IS getting installed properly into the container.

For a while, we thought maybe we still needed to list: MAVSDK::mavsdk_mission. (or _action, _offboard, _telemetry) inside the target_link_libraries() as we saw that in some older examples, but apparently that’s all been pulled into 1 library with these newer versions, so that wasn’t it.

I’m really at a dead end here and everything we have tried (including manually stating where MAVSDK is inside the CMakeLists.txt) hasn’t worked.

Coming up on a huge deadline and really need to get this working.

Anyone have any ideas? Everyone in my office who has looked at it is equally stumped and by all accounts it SHOULD be working properly…

Any help is greatly appreciated!


IMO the error you mentionned is due to missing header file in folder /usr/include/mavsdk if I’m not mistaken

Nevermind, we FINALLY figured it out… Had to do with the way we were trying to get the Telemetry/Mission/Action/Offboard objects and their shared_ptrs.

Will somebody PLEASE fix the examples? The offboard (and likely many others) are out of date and make a lot of function calls to class methods that no longer exist. Documentation and examples across the board on MavSDK seem to be all over the place and often contradictory.

Yup, they’re there… that wasn’t the source of the problem… Thanks though!

I hear you. I think the problem you ran into is the fact that the main branch is going to be released as v2, and you might be installing and linking against v1.4.

I’m sorry that v2 takes a while. If you want to allow me to spend more time on it, consider sponsoring my open source work.