3

I created a ros catkin package and successfully imported it to QtCreator. Despite there is no problem with the compilation, the include directories mentioned in the CMakeLists file of my package are not indexed.

What might be the problem? Please let me know if you need more information.

in4001
  • 656
  • 6
  • 24

2 Answers2

1

This is a bit annoying with QtCreator. For the header files in the include directory to be found, they have to be listed in the add_executable / add_library explicitly.

I usually use the following simple (although maybe a bit dirty) solution:

file(GLOB_RECURSE HEADERS include/*.hpp include/*.h)

add_executable(compute_rigid_object
  ${HEADERS} # for qtcreator...
  src/the_source_files.cpp
  ...
)
luator
  • 4,769
  • 3
  • 30
  • 51
0

Create a library from your class files and link the library to the main executable. Then the auto-completion is working in QtCreator.

Here how the CMakeLists.txt could look:

cmake_minimum_required(VERSION 2.8.3)
project(example_project)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

find_package(catkin REQUIRED COMPONENTS
  roscpp
)

catkin_package()

include_directories(
  include
  ${catkin_INCLUDE_DIRS}
  ${PROJECT_SOURCE_DIR}
)

# Create a library with all your classes
add_library(myFilesLib
    src/class1.cpp
    src/class2.cpp
    src/class3.cpp
)
target_link_libraries(myFilesLib
    ${catkin_LIBRARIES}
)

# add your executable
add_executable(${PROJECT_NAME}
    src/main.cpp
)

# link the library with your classes to the executable
target_link_libraries(${PROJECT_NAME}
  ${catkin_LIBRARIES}
  myFilesLib
)

I had a same/similar problem. See the more detailed explanation of the solution here.

Community
  • 1
  • 1
jonas-
  • 56
  • 7