Skip to content

Compile err “undefined reference to `SSL_get0_group_name'” when using as a sub_dir of a cmake project #2696

@Staok

Description

@Staok

modify the file MAVSDK-xxx/src/mavsdk/core/CMakeLists.txt:
-P ${CMAKE_SOURCE_DIR}/cmake/generate_embedded_xml.cmake
change to:
-P ${PROJECT_SOURCE_DIR}/../cmake/generate_embedded_xml.cmake

so that this lib be used as a sub_dir of a cmake project:

cmake_minimum_required(VERSION 3.15)
project(mavsdk_lib_pkg_cpp)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
#   add_compile_options(-Wall -Wextra -Wpedantic)
# endif()

# add_definitions("-Wall -Wextra")

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)

# config "MAVSDK" build options
set(SUPERBUILD ON CACHE BOOL "")
set(BUILD_MAVSDK_SERVER OFF CACHE BOOL "")
set(BUILD_WITH_PROTO_REFLECTION OFF CACHE BOOL "")
set(BUILD_SHARED_LIBS ON CACHE BOOL "")
# set(MAVLINK_DIALECT common CACHE STRING "") keep default
set(BUILD_TESTING OFF CACHE BOOL "")
set(BUILD_WITHOUT_CURL OFF CACHE BOOL "")

# set(CMAKE_BUILD_TYPE Release CACHE STRING "")

add_subdirectory(
    ${CMAKE_CURRENT_SOURCE_DIR}/src/MAVSDK-3.10.2
)

add_executable(test_MAVSDK src/test_MAVSDK.cpp)
target_include_directories(test_MAVSDK PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include/${PROJECT_NAME}>)
target_compile_features(test_MAVSDK PUBLIC c_std_99 cxx_std_17)  # Require C99 and C++17
target_link_libraries(
  test_MAVSDK
  ${rclcpp_TARGETS}
  mavsdk
)
...

and get err:

kanbai@StaokDesktop:~/rover_app_ros2_ws$ colcon build --packages-select mavsdk_lib_pkg_cpp --event-handlers console_direct+
Starting >>> mavsdk_lib_pkg_cpp
[  0%] Built target generate_core_mavlink_xml_header   
[ 57%] Built target mavsdk                                
[ 58%] Built target test_MAVSDK
[ 58%] Linking CXX executable system_tests_runner          
/usr/bin/ld: ../mavsdk/libmavsdk.so.75682307-dirty.75682307-dirty.75682307-dirty: undefined reference to `SSL_get0_group_name'
collect2: error: ld returned 1 exit status                 
gmake[2]: *** [src/MAVSDK-3.10.2/src/system_tests/CMakeFiles/system_tests_runner.dir/build.make:551: src/MAVSDK-3.10.2/src/system_tests/system_tests_runner] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:1111: src/MAVSDK-3.10.2/src/system_tests/CMakeFiles/system_tests_runner.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
--- stderr: mavsdk_lib_pkg_cpp
/usr/bin/ld: ../mavsdk/libmavsdk.so.75682307-dirty.75682307-dirty.75682307-dirty: undefined reference to `SSL_get0_group_name'
collect2: error: ld returned 1 exit status
gmake[2]: *** [src/MAVSDK-3.10.2/src/system_tests/CMakeFiles/system_tests_runner.dir/build.make:551: src/MAVSDK-3.10.2/src/system_tests/system_tests_runner] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:1111: src/MAVSDK-3.10.2/src/system_tests/CMakeFiles/system_tests_runner.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
---
Failed   <<< mavsdk_lib_pkg_cpp [2.05s, exited with code 2]

Summary: 0 packages finished [2.30s]
  1 package failed: mavsdk_lib_pkg_cpp
  1 package had stderr output: mavsdk_lib_pkg_cpp

os:

kanbai@StaokDesktop:~/rover_app_ros2_ws$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 24.04.3 LTS
Release:        24.04
Codename:       noble

kanbai@StaokDesktop:~/rover_app_ros2_ws$ cat /proc/version
Linux version 6.6.87.2-microsoft-standard-WSL2 (root@439a258ad544) (gcc (GCC) 11.2.0, GNU ld (GNU Binutils) 2.37) #1 SMP PREEMPT_DYNAMIC Thu Jun  5 18:30:46 UTC 2025

cmake version:

kanbai@StaokDesktop:~/rover_app_ros2_ws$ cmake --version
cmake version 3.28.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).

adding this in MAVSDK dir src/CMakeLists.txt: #2489

find_package(OpenSSL REQUIRED)
message(STATUS " === OPENSSL_FOUND: ${OPENSSL_FOUND}")
message(STATUS " === OPENSSL_INCLUDE_DIR: ${OPENSSL_INCLUDE_DIR}")
message(STATUS " === OPENSSL_CRYPTO_LIBRARY: ${OPENSSL_CRYPTO_LIBRARY}")
message(STATUS " === OPENSSL_CRYPTO_LIBRARIES: ${OPENSSL_CRYPTO_LIBRARIES}")
message(STATUS " === OPENSSL_SSL_LIBRARY: ${OPENSSL_SSL_LIBRARY}")
message(STATUS " === OPENSSL_SSL_LIBRARIES: ${OPENSSL_SSL_LIBRARIES}")
message(STATUS " === OPENSSL_LIBRARIES: ${OPENSSL_LIBRARIES}")
message(STATUS " === OPENSSL_VERSION: ${OPENSSL_VERSION}")
message(STATUS " === OPENSSL_APPLINK_SOURCE: ${OPENSSL_APPLINK_SOURCE}")

and get:

--  === OPENSSL_FOUND: TRUE
--  === OPENSSL_INCLUDE_DIR: /usr/include
--  === OPENSSL_CRYPTO_LIBRARY: /usr/lib/x86_64-linux-gnu/libcrypto.so
--  === OPENSSL_CRYPTO_LIBRARIES: /usr/lib/x86_64-linux-gnu/libcrypto.so
--  === OPENSSL_SSL_LIBRARY: /usr/lib/x86_64-linux-gnu/libssl.so
--  === OPENSSL_SSL_LIBRARIES: /usr/lib/x86_64-linux-gnu/libssl.so
--  === OPENSSL_LIBRARIES: /usr/lib/x86_64-linux-gnu/libssl.so;/usr/lib/x86_64-linux-gnu/libcrypto.so
--  === OPENSSL_VERSION: 3.0.13
--  === OPENSSL_APPLINK_SOURCE: 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions