Ask Your Question
0

Undefined reference when compiling my own packages with external package

asked 2021-09-03 21:00:59 -0600

xingkai gravatar image

Hi everyone, I am facing a problem when compiling packages that using libdatachannel as a dependence.

I am trying to use libdatachannel to develop a node in ROS2 which is going to have the ability to communicate each other with P2P connection. I am not sure if here is a good place to ask something about libdatachannel alone with ROS2 development, but I am going to start here.

so I installed libdatachannel with prefix to ROS2 directory:


Install the project...
-- Install configuration: ""
-- Installing: /opt/ros/dashing/lib/libdatachannel.so.0.14.2
-- Installing: /opt/ros/dashing/lib/libdatachannel.so
-- Installing: /opt/ros/dashing/include/rtc/candidate.hpp
-- Installing: /opt/ros/dashing/include/rtc/channel.hpp
-- Installing: /opt/ros/dashing/include/rtc/configuration.hpp
-- Up-to-date: /opt/ros/dashing/include/rtc/configuration.hpp
-- Installing: /opt/ros/dashing/include/rtc/datachannel.hpp
-- Installing: /opt/ros/dashing/include/rtc/description.hpp
-- Installing: /opt/ros/dashing/include/rtc/mediahandler.hpp
-- Installing: /opt/ros/dashing/include/rtc/rtcpreceivingsession.hpp
-- Installing: /opt/ros/dashing/include/rtc/common.hpp
-- Installing: /opt/ros/dashing/include/rtc/global.hpp
-- Installing: /opt/ros/dashing/include/rtc/message.hpp
-- Installing: /opt/ros/dashing/include/rtc/peerconnection.hpp
-- Installing: /opt/ros/dashing/include/rtc/reliability.hpp
-- Installing: /opt/ros/dashing/include/rtc/rtc.h
-- Installing: /opt/ros/dashing/include/rtc/rtc.hpp
-- Installing: /opt/ros/dashing/include/rtc/rtp.hpp
-- Installing: /opt/ros/dashing/include/rtc/track.hpp
-- Installing: /opt/ros/dashing/include/rtc/websocket.hpp
-- Installing: /opt/ros/dashing/include/rtc/websocketserver.hpp
-- Installing: /opt/ros/dashing/include/rtc/rtppacketizationconfig.hpp
-- Installing: /opt/ros/dashing/include/rtc/rtcpsrreporter.hpp
-- Installing: /opt/ros/dashing/include/rtc/rtppacketizer.hpp
-- Installing: /opt/ros/dashing/include/rtc/opusrtppacketizer.hpp
-- Installing: /opt/ros/dashing/include/rtc/opuspacketizationhandler.hpp
-- Installing: /opt/ros/dashing/include/rtc/h264rtppacketizer.hpp
-- Installing: /opt/ros/dashing/include/rtc/nalunit.hpp
-- Installing: /opt/ros/dashing/include/rtc/h264packetizationhandler.hpp
-- Installing: /opt/ros/dashing/include/rtc/mediachainablehandler.hpp
-- Installing: /opt/ros/dashing/include/rtc/mediahandlerelement.hpp
-- Installing: /opt/ros/dashing/include/rtc/mediahandlerrootelement.hpp
-- Installing: /opt/ros/dashing/include/rtc/rtcpnackresponder.hpp
-- Installing: /opt/ros/dashing/include/rtc/utils.hpp
-- Installing: /opt/ros/dashing/share/cmake/libdatachannel/libdatachannel-config.cmake
-- Installing: /opt/ros/dashing/share/cmake/libdatachannel/libdatachannel-config-noconfig.cmake

Seems all files are installed successfully into the ROS2 directory.

In the CMakeLists.txt file of my package, I used find_package(LibDatachannel REQUIRED) and find_package(nlohmann_json 3.2.0 REQUIRED) to find the external packages. These command are going to search libdatachannel and json package in /opt/ros/dashing. Then I use ament_target_dependencies() to link the library. It is merely an ament macro that is similar to target_link_libraries(). Below is my CMakeLists.txt file:

cmake_minimum_required(VERSION 3.5)
project(webrtc_package_cpp)

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 17)
endif()

    if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
      add_compile_options(-Wall -Wextra -Wpedantic)
    endif()
    set(nlohmann_json_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include/libdatachannel/deps/json/install)
    # find dependencies
    find_package(ament_cmake REQUIRED)
    find_package(rclcpp ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-09-22 01:55:21 -0600

I don't believe that libdatachannel can be targeted directly using ament_target_dependencies like that. Some non-ament packages work with that macro, but others do not.

A brief search leads me to suggest that using LibDataChannel::datachannel in place of libdatachannel might work, but if it doesn't, you might need to target LibDataChannel::datachannel using target_link_libraries instead of ament_target_dependencies (as it is not actually an ament package).

edit flag offensive delete link more

Comments

Thank you so much, it solves my problem perfectly!! I used target_link_libraries to link LibDataChannel::LibDataChannel, and everything works fine.

xingkai gravatar image xingkai  ( 2021-09-23 18:09:31 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-09-03 21:00:59 -0600

Seen: 38 times

Last updated: Sep 22