ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Custom class in C++ nodes [closed]

asked 2015-01-28 12:35:19 -0500

Robot_Cpak gravatar image

I wrote a class with some functionality I want to use in a few of my ROS nodes, but I'm having trouble getting catkin to generate the proper files, or I'm including things wrong, or something... So far, I've been able to get catkin to compile a library from my class, which is a .so file, but then I'm struggling with using this class in any of my nodes because it lacks a .h file. Am I going about this the wrong way?

Here's the CMakeLists.txt that succeeds in generating a library .so file, but no .h file.

cmake_minimum_required(VERSION 2.8.3)
project(LogixEIP)

find_package(catkin REQUIRED COMPONENTS
  roscpp
)

catkin_package(
  INCLUDE_DIRS include
  LIBRARIES LogixEIP
  CATKIN_DEPENDS roscpp
  DEPENDS system_lib
)

include_directories(
  ${catkin_INCLUDE_DIRS}
)

 add_library(LogixEIP
   src/LogixEIP.cpp
 )

## Mark executables and/or libraries for installation
 install(TARGETS LogixEIP
   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
 )
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Robot_Cpak
close date 2016-11-03 09:52:02.601318

Comments

2

Do you have a header file? Or are you expecting CMake/catkin to generate one for you? You have to write, install, and include the header file with the class prototype in it for other software to make use of your .so.

William gravatar image William  ( 2015-01-28 13:25:09 -0500 )edit

I was hoping that catkin would generate one for me, is that possible?

Robot_Cpak gravatar image Robot_Cpak  ( 2015-01-28 13:40:36 -0500 )edit

No, this is not something catkin nor CMake does. This is a C++ issue. I would suggest looking elsewhere: http://stackoverflow.com/questions/42...

William gravatar image William  ( 2015-01-28 13:57:54 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2015-01-29 05:28:05 -0500

Wolf gravatar image

updated 2015-01-29 12:32:07 -0500

William gravatar image

Change

include_directories(
  ${catkin_INCLUDE_DIRS}
)

for

include_directories(
  ${catkin_INCLUDE_DIRS}
 include
)

Note that

catkin_package(
  INCLUDE_DIRS include
  LIBRARIES LogixEIP
  CATKIN_DEPENDS roscpp
  DEPENDS system_lib
)

makes source files in dependend packages of your first package finding the headers in the include folder of your first package while

include_directories(
  ${catkin_INCLUDE_DIRS}
 include
)

makes source files in your first package finding the headers in the include folder of your first package. Source files in your package most likely also use the headers in the same package.....

edit flag offensive delete link more
3

answered 2015-01-28 13:48:21 -0500

I'm not sure I fully understand the question, but if your header file doesn't exist, Catkin won't attempt to create one for you by scraping your .cpp file. You'll need to manually create a header file for your class. Then the catkin/cmake command referring to FILES_MATCHING_PATTERN "*.h" listed in your question will work.

edit flag offensive delete link more
2

answered 2015-01-28 14:16:36 -0500

Robot_Cpak gravatar image

Catkin/Eclipse will not auto-generate a header file from a .cpp file, but Eclipse will generate method stubs from a header file.

Add function prototype to .h file "void foobar();"
Select the function name "foobar" (try double clicking)
In the toolbar click Source -> Implement Method

from here: http://stackoverflow.com/questions/23...

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-01-28 12:35:19 -0500

Seen: 2,733 times

Last updated: Jan 29 '15