Ask Your Question
0

Unable to include C++ header file while compiling

asked 2019-06-20 10:11:19 -0600

Dickson gravatar image

updated 2019-06-20 10:12:47 -0600

gvdhoorn gravatar image

There are 2 files in my package

  1. A c++ class file (example_ros_class.cpp)
  2. roscpp file that uses the header of the first file (implementation.cpp)

    using catkin_make, i receive this error code

Here's the error code

fatal error: example_ros_class.h: No such file or directory
 #include "example_ros_class.h"

I have tried to follow this documentation

and so fort

Here's my CMake

cmake_minimum_required(VERSION 2.8.3)

project(eg_ros_class)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
)

catkin_package(
  INCLUDE_DIRS include
  LIBRARIES eg_ros_class
  CATKIN_DEPENDS roscpp std_msgs
  DEPENDS system_lib
)

##BUILD##
include_directories(
  include
  src/eg_ros_class
  ${catkin_INCLUDE_DIRS}
  ${Boost_INCLUDE_DIRS}
  ${GSTREAMER_INCLUDE_DIRS}
)

add_library(eg_ros_class src/example_ros_class.cpp)

add_executable(eg_ros_class_exe src/example_ros_class.cpp)
target_link_libraries(eg_ros_class ${catkin_LIBRARIES}, )

add_executable(implementation_exe src/implementation.cpp)
target_link_libraries(implementation_exe ${catkin_LIBRARIES})
add_dependencies(implementation_exe eg_ros_class_generate_messages_cpp)

##Install##
catkin_package(INCLUDE_DIRS include
               LIBRARIES eg_ros_class)
 install(TARGETS eg_ros_class
   ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
   LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
   RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
 )

 install(DIRECTORY include/${PROJECT_NAME}/
   DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
   FILES_MATCHING PATTERN "*.h"
   PATTERN ".svn" EXCLUDE
 )
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-06-21 00:21:47 -0600

abrzozowski gravatar image

updated 2019-06-21 00:32:42 -0600

My answer is just guessing, so i point out certain potential concerns related to your implementation, in numbered points.

  1. You should paste a bigger piece of error message.

    If you have only two files in your package, most likely you have #include "example_ros_class.h" in the example_ros_class.cpp resulting in fatal error: example_ros_class.h: No such file or directory

  2. Your CMakeLists.txt contains a lot of mistakes

A fixed file would look like this

cmake_minimum_required(VERSION 2.8.3)

project(eg_ros_class)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
)

catkin_package(
  # (A) INCLUDE_DIRS include
  LIBRARIES eg_ros_class
  CATKIN_DEPENDS roscpp std_msgs
  # (B) DEPENDS system_lib
)

##BUILD##
include_directories(
  include
  # (C) src/eg_ros_class
  ${catkin_INCLUDE_DIRS}
  # (D) ${Boost_INCLUDE_DIRS}
  # (E) ${GSTREAMER_INCLUDE_DIRS}
)

add_library(eg_ros_class src/example_ros_class.cpp)

add_executable(eg_ros_class_exe src/example_ros_class.cpp)
# (F) target_link_libraries(eg_ros_class ${catkin_LIBRARIES}, )
target_link_libraries(eg_ros_class ${catkin_LIBRARIES})

add_executable(implementation_exe src/implementation.cpp)
target_link_libraries(implementation_exe ${catkin_LIBRARIES})
add_dependencies(implementation_exe eg_ros_class_generate_messages_cpp)

##Install##
# (G)
#catkin_package(INCLUDE_DIRS include
#               LIBRARIES eg_ros_class)
# install(TARGETS eg_ros_class
#   ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
# install(DIRECTORY include/${PROJECT_NAME}/
#   DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
#   FILES_MATCHING PATTERN "*.h"
#   PATTERN ".svn" EXCLUDE
# )E_BIN_DESTINATION}
# )
# install(DIRECTORY include/${PROJECT_NAME}/
#   DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
#   FILES_MATCHING PATTERN "*.h"
#   PATTERN ".svn" EXCLUDE
# )

2 A. You wrote that your project contains only two files, so include directory is empty. In this case this line is not needed.

2 B. What is a system_lib? It's probably the name used as an example in the template CMakeLists.txt.

2 C. In this line you should include only headers

2 D and 2E. It depends on if you using Boost or GStreamer library. Are you using?

2 F. Freaky comma before parenthesis. Fixed in the next line: target_link_libraries(eg_ros_class ${catkin_LIBRARIES})

2 G. You don't need use catkin_package again

edit flag offensive delete link more

Comments

Hello! Thank you for your guidance

I manage to get it working now. Just using

include_directories( include ${eg_ros_class} #package_name ${catkin_INCLUDE_DIRS} )

Dickson gravatar imageDickson ( 2019-06-23 23:45:52 -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

Stats

Asked: 2019-06-20 10:11:19 -0600

Seen: 58 times

Last updated: Jun 21