Robotics StackExchange | Archived questions

No matching function for advertiseService

Hi!

I am trying to add a service to the Kinect2 Bridge of the iaikinect2 project. This class does not have a header file but is defined entirely in kinect2bridge.cpp. It looks somewhat like this:

// includes
class Kinect2Bridge
{
  private: 
      // many private member variables
      ros::ServiceServer reconnectService;  // added by me
  public:
  Kinect2Bridge(const ros::NodeHandle &nh = ros::NodeHandle(), const ros::NodeHandle &priv_nh = ros::NodeHandle("~"))
    :  /*  many assignments here*/
  {
    status.resize(COUNT, UNSUBCRIBED);
    reconnectService = nh.advertiseService("myservice", &Kinect2Bridge::myserviceCallback, this);  // added by me
  }
  // many functions here
  bool myserviceCallback(kinect2_bridge::myservice::Request &req, kinect2_bridge::myservice::Response &res)
  {
    ROS_INFO("Request received.");
    return true;
  }
}

This however does not compile as no matching function to call for advertiseService is found. I don't understand why. Maybe this is due to the inline declaration and definition of functions and hence their type can't be correctly deduced?

As requested in comments, here is the corresponding CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(kinect2_bridge CXX)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBT_USE_DOUBLE_PRECISION -Wall")
# Unused warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wuninitialized -Winit-self -Wunused-function -Wunused-label -Wunused-variable -Wunused-but-set-variable -Wunused-but-set-parameter")
# Additional warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Warray-bounds -Wtype-limits -Wreturn-type -Wsequence-point -Wparentheses -Wmissing-braces -Wchar-subscripts -Wswitch -Wwrite-strings -Wenum-compare -Wempty-body -Wlogical-op")

# Check for c++11 support
INCLUDE(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
IF(COMPILER_SUPPORTS_CXX11)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
ELSEIF(COMPILER_SUPPORTS_CXX0X)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
ELSE()
  MESSAGE(ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
ENDIF()

find_package(freenect2 REQUIRED HINTS "$ENV{HOME}/freenect2")

find_package(catkin REQUIRED COMPONENTS roscpp rostime tf std_msgs sensor_msgs nodelet cv_bridge compressed_depth_image_transport kinect2_registration message_generation)

## System dependencies are found with CMake's conventions
find_package(OpenCV REQUIRED)

################################################
## Declare ROS messages, services and actions ##
################################################
add_service_files(
  FILES
  myservice.srv
)
generate_messages(DEPENDENCIES std_msgs)

###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if you package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
  INCLUDE_DIRS include
#  LIBRARIES kinect2_bridge
  CATKIN_DEPENDS kinect2_registration
#  DEPENDS system_lib
)

###########
## Build ##
###########

# Display additional files in qtcreator
execute_process(COMMAND find ${PROJECT_SOURCE_DIR} -type f OUTPUT_VARIABLE FILES_STRING)
string(REPLACE "\n" ";" FILES_LIST ${FILES_STRING})
add_custom_target(additional_files_${PROJECT_NAME}
  SOURCES
  ${FILES_LIST}
  ${PROJECT_SOURCE_DIR}/../README.md
)

include_directories(include
  ${catkin_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS}
  ${freenect2_INCLUDE_DIRS}
  ${kinect2_registration_INCLUDE_DIRS}
)

if(DEPTH_REG_OPENCL)
  add_definitions(-DDEPTH_REG_OPENCL)
endif()
if(DEPTH_REG_CPU)
  add_definitions(-DDEPTH_REG_CPU)
endif()
add_definitions(-DK2_CALIB_PATH="${PROJECT_SOURCE_DIR}/data/")

add_library(kinect2_bridge_nodelet SHARED src/kinect2_bridge.cpp)
add_dependencies(
        kinect2_bridge_nodelet
)
target_link_libraries(kinect2_bridge_nodelet
  ${catkin_LIBRARIES}
  ${OpenCV_LIBRARIES}
  ${freenect2_LIBRARY}
  ${kinect2_registration_LIBRARY}
)

add_executable(kinect2_bridge src/kinect2_bridge.cpp)
add_dependencies(
        kinect2_bridge
)
target_link_libraries(kinect2_bridge
  ${catkin_LIBRARIES}
  ${OpenCV_LIBRARIES}
  ${freenect2_LIBRARY}
  ${kinect2_registration_LIBRARY}
)

#############
## Install ##
#############

# all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html

## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# install(PROGRAMS
#   scripts/my_python_script
#   DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Mark executables and/or libraries for installation
install(TARGETS kinect2_bridge kinect2_bridge_nodelet
#   ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

## Mark cpp header files for installation
install(DIRECTORY include/${PROJECT_NAME}/
  DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
  FILES_MATCHING PATTERN "*.h"
  PATTERN ".svn" EXCLUDE
)

## Mark other files for installation (e.g. launch and bag files, etc.)
install(DIRECTORY
  launch
  # myfile2
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
install(FILES
  nodelet_plugins.xml
  # myfile2
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

#############
## Testing ##
#############

## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_kinect2_bridge.cpp)
# if(TARGET ${PROJECT_NAME}-test)
#   target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()

## Add folders to be run by python nosetests
# catkin_add_nosetests(test)

Asked by JayDe on 2019-12-19 04:09:24 UTC

Comments

@JayDe can you provide us with your CMakeLists.txt file?

Asked by l4ncelot on 2019-12-19 07:33:57 UTC

@l4ncelot okay, I edited my question :)

Asked by JayDe on 2019-12-19 07:41:03 UTC

Idk if it's gonna fix the issue. But you're not adding any dependencies in lines

add_dependencies(
        kinect2_bridge_nodelet
)

and

add_dependencies(
        kinect2_bridge
)

Asked by l4ncelot on 2019-12-19 10:16:29 UTC

Hey, thanks, but no, that does not help.

Asked by JayDe on 2019-12-19 10:19:49 UTC

Answers