0
$\begingroup$

Rosanswers logo

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
 )

Originally posted by Robot_Cpak on ROS Answers with karma: 71 on 2015-01-28

Post score: 0


Original comments

Comment by William on 2015-01-28:
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.

Comment by Robot_Cpak on 2015-01-28:
I was hoping that catkin would generate one for me, is that possible?

Comment by William on 2015-01-28:
No, this is not something catkin nor CMake does. This is a C++ issue. I would suggest looking elsewhere: http://stackoverflow.com/questions/42770/writing-using-c-libraries

$\endgroup$

3 Answers 3

0
$\begingroup$

Rosanswers logo

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.....


Originally posted by Wolf with karma: 7555 on 2015-01-29

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$
0
$\begingroup$

Rosanswers logo

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.


Originally posted by Morgan with karma: 521 on 2015-01-28

This answer was NOT ACCEPTED on the original site

Post score: 3

$\endgroup$
0
$\begingroup$

Rosanswers logo

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/2322705/auto-generate-header-files-for-a-c-source-file-in-an-ide


Originally posted by Robot_Cpak with karma: 71 on 2015-01-28

This answer was NOT ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.