0

I have a qt GUI project based on ROS(catkin), it is my cmake

cmake_minimum_required(VERSION 2.8.0)
project(jir_seg)

find_package(catkin REQUIRED COMPONENTS qt_build roscpp)
include_directories(${catkin_INCLUDE_DIRS})

catkin_package()

rosbuild_prepare_qt4(QtCore QtGui)

file(GLOB QT_FORMS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ui/*.ui)
file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} resources/*.qrc)
file(GLOB_RECURSE QT_MOC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS      include/jir_seg/*.hpp)

QT4_ADD_RESOURCES(QT_RESOURCES_CPP ${QT_RESOURCES})
QT4_WRAP_UI(QT_FORMS_HPP ${QT_FORMS})
QT4_WRAP_CPP(QT_MOC_HPP ${QT_MOC})

file(GLOB_RECURSE QT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/*.cpp)

add_executable(jir_seg ${QT_SOURCES} ${QT_RESOURCES_CPP} ${QT_FORMS_HPP} ${QT_MOC_HPP})
target_link_libraries(jir_seg ${QT_LIBRARIES} ${catkin_LIBRARIES} )
install(TARGETS jir_seg RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

it's auto generated cmake in catkin, in my project i have a subclass from qgeraphicview (JIRSEGSubClassQGV.hpp) that i promoted a widget to it, the problem is when i compiled this code i get this error

In file included from /home/vahid/catkin_ws/src/jir_seg/src/../include/jir_seg  /JIRSEG2DWindow.hpp:14:0,
             from /home/vahid/catkin_ws/src/jir_seg/src/JIRSEG2DWindow.cpp:1:
/home/vahid/catkin_ws/build/jir_seg/ui_JIRSEG2DWindow.h:26:33: fatal error:   JIRSEGSubClassQGV.hpp: No such file or directory
compilation terminated.
In file included from /home/vahid/catkin_ws/src/jir_seg/src/../include/jir_seg/JIRSEG2DWindow.hpp:14:0,
             from /home/vahid/catkin_ws/src/jir_seg/src/../include/jir_seg/JIRSEGMainWindow.hpp:9,
             from /home/vahid/catkin_ws/src/jir_seg/src/JIRSEGMainWindow.cpp:1:
/home/vahid/catkin_ws/build/jir_seg/ui_JIRSEG2DWindow.h:26:33: fatal error:  JIRSEGSubClassQGV.hpp: No such file or directory
compilation terminated.
In file included from /home/vahid/catkin_ws/src/jir_seg/src/../include/jir_seg  /JIRSEG2DWindow.hpp:14:0,
             from /home/vahid/catkin_ws/src/jir_seg/src/../include/jir_seg  /JIRSEGMainWindow.hpp:9,
             from /home/vahid/catkin_ws/src/jir_seg/src/main.cpp:5:
/home/vahid/catkin_ws/build/jir_seg/ui_JIRSEG2DWindow.h:26:33: fatal error:   JIRSEGSubClassQGV.hpp: No such file or directory
compilation terminated.
make[2]: *** [jir_seg/CMakeFiles/jir_seg.dir/src/JIRSEGMainWindow.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [jir_seg/CMakeFiles/jir_seg.dir/src/JIRSEG2DWindow.cpp.o] Error 1
make[2]: *** [jir_seg/CMakeFiles/jir_seg.dir/src/main.cpp.o] Error 1
make[1]: *** [jir_seg/CMakeFiles/jir_seg.dir/all] Error 2
make: *** [all] Error 2

the header that UIC adds to ui_*.h is '#include "JIRSEGSubClassQGV.hpp"', i tried some ways to solve but none of them doesn't work, any help appreciated.

Vahid
  • 76
  • 6
  • I'm not sure, but may be [explicit reference on path of include files](http://www.cmake.org/cmake/help/v2.8.8/cmake.html#command:include_directories) helps. – Gluttton Jun 14 '14 at 16:53
  • thank you so much, also i tried this include_directories(${CMAKE_CURRENT_SOURCE_DIR}) set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/jir_seg/JIRSEGSubClassQGV.hpp), but also it doesn't work, i'm not sure but i think i do sth wrong that i can't find it!! – Vahid Jun 14 '14 at 17:00
  • Do you try `include_directories(${CMAKE_CURRENT_SOURCE_DIR})` and `include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)` and `include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/jir_seg)` - all three directives at the same time? – Gluttton Jun 14 '14 at 17:28
  • And try replace `CMAKE_CURRENT_SOURCE_DIR` on `PROJECT_SOURCE_DIR`. Usually I use only `PROJECT_SOURCE_DIR`. – Gluttton Jun 14 '14 at 17:38
  • Thank you so so much, it was taking my time about 5 hours, the first hierarchical directive has solved my problem, please write it as answer for taking point :) – Vahid Jun 14 '14 at 17:41

2 Answers2

2

The CMake has no idea about purpose of directories, so if you put header files inside subdirectory include, you must notify CMake about this using iclude_directories directive:

include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/jir_seg)

Gluttton
  • 5,739
  • 3
  • 31
  • 58
0

I'm using Qt 6.4.0, Qt Creator 9.0.1 and CMake 3.22.1 and we STILL have the same problem in 2022. I have looked through all the CMake files etc. and I couldn't find a way to add any paths. My solution was to put the FULL path of the 'missing' header file in the promote box and not just the name. Qt, or one of it's compilers doesn't know that the header file is in the source folder (at least in my case) and I couldn't find a way to tell it. It's already in CMakeLists.txt but that seems to be ignored. This solution works for me but I'd be happy to try other suggestions.

I found that adding the line: target_include_directories(executable PRIVATE ${PROJECT_SOURCE_DIR}) to CMakeLists.txt somewhere after PROGRAM_SOURCES is declared works and the promoted widgets compile properly.

Colins2
  • 11
  • 3
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 29 '22 at 07:07