Pytanie nie można dołączyć nagłówka ui_form QT5 w cmake


Mój CMakeLists.txt wygląda mniej więcej tak:

cmake_minimum_required(VERSION 2.8)
if(CMAKE_BUILD_TYPE STREQUAL Release)
  SET(CMAKE_BUILD_TYPE Release)
  SET (PROJECT_NAME location_recognition)
  message("Release mode")
else()
  SET(CMAKE_BUILD_TYPE Debug)
  SET (PROJECT_NAME location_recognition)
  SET(CMAKE_CXX_FILES "-g -Wall")
  message("Debug mode")

endif()

#find QT libraries
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)

FIND_PACKAGE(OpenCV REQUIRED)
FIND_PACKAGE(Boost REQUIRED)

# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)

# As moc files are generated in the binary dir, tell CMake
# to always look for includes there:
set(CMAKE_INCLUDE_CURRENT_DIR ON)
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} )
# We need add -DQT_WIDGETS_LIB when using QtWidgets in Qt 5.
add_definitions(${Qt5Widgets_DEFINITIONS})

SET(SRC
  src/voting_classifier.cpp
  src/voting_classifier_helper.cpp
  src/results_scene.cpp
  src/image_window_widget.cpp
  src/image_result_matrix.cpp
  src/location_recognition.cpp
  src/main.cpp
  )

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

FIND_PROGRAM(QT_UIC_EXECUTABLE uic
  $ENV{QTDIR}/bin
  )

IF (QT_UIC_EXECUTABLE)
  # SET ( QT_WRAP_UI "YES")
  message("WOW")
ENDIF (QT_UIC_EXECUTABLE)

QT5_WRAP_UI(image_result_matrix.h ui_forms/image_result_matrix.ui -o ui_forms/image_result_matrix.h)
QT5_WRAP_UI(image_window_widget.h ui_forms/image_window_widget.ui -o ui_forms/image_window_widget.h)
QT5_WRAP_UI(location_recognition.h ui_forms/location_recognition.ui -o ui_forms/location_recognition.h)
QT5_WRAP_UI(ui_results_view.h ui_forms/result_view.ui -o ui_forms/ui_results_view.h)

include_directories(${PROJECT_SOURCE_DIR}/include
  ${PROJECT_SOURCE_DIR}/ui_forms
  ${PROJECT_SOURCE_DIR}
  ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS}
  ${PROJECT_SOURCE_DIR}/../perception_kit/utilities/include
  ${PROJECT_SOURCE_DIR}/../perception_kit/visual_categorization/include
  ${OpenCV_INCLUDE_DIRS})

FIND_LIBRARY(utilities NAMES libperception_kitutilities.so PATHS "/other/workspace/perception/perception_kit/utilities/lib")
FIND_LIBRARY(utilitiesd NAMES libperception_kitutilitiesd.so PATHS "/other/workspace/perception/perception_kit/utilities/lib")

message("Utilites Libs :${utilities}")

FIND_LIBRARY(visual_categorization NAMES libperception_kitvisual_categorization.so PATHS "/other/workspace/perception/perception_kit/visual_categorization/lib")
FIND_LIBRARY(visual_categorizationd NAMES libperception_kitvisual_categorizationd.so PATHS "/other/workspace/perception/perception_kit/visual_categorization/lib")
message("Visual_categorization Libs :${visual_categorization}")

SET(LINK_LIBRARY optimized ${utilities} ${visual_categorization} debug ${utilities} ${visual_categorizationd})
# set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${perception_kit_VERSION} )
add_executable(location_recognition ${SRC})
target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARY}
  ${OpenCV_LIBS} ${Boost_LIBS})

qt5_use_modules(location_recognition Core Gui Widgets)

kiedy robię

cmake .

to działa dobrze. Ale kiedy próbuję make nadal stwierdza, że ​​nagłówek ui_forms / *. h nie został znaleziony i nie powiedzie się.

W pliku dołączonym od   /other/workspace/perception/location_recognition/src/results_scene.cpp:4:0:   /other/workspace/perception/location_recognition/include/perception_kit/location_recognition/results_scene.h:6:29:   błąd krytyczny: ui_results_view.h: Brak takiej kompilacji plików lub katalogów   zakończony. zrobić [2]: *   [CMakeFiles / location_recognition.dir / src / results_scene.cpp.o] Błąd 1   make [1]: * [CMakeFiles / location_recognition.dir / all] Błąd 2:    * [all] Błąd 2

kiedy robię "make VERBOSE = 1" dostaję

/usr/local/bin/cmake -H/other/workspace/perception/location_recognition -B/other/workspace/perception/location_recognition --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/bin/cmake -E cmake_progress_start /other/workspace/perception/location_recognition/CMakeFiles /other/workspace/perception/location_recognition/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/other/workspace/perception/location_recognition'
make -f CMakeFiles/location_recognition_automoc.dir/build.make CMakeFiles/location_recognition_automoc.dir/depend
make[2]: Entering directory `/other/workspace/perception/location_recognition'
cd /other/workspace/perception/location_recognition && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /other/workspace/perception/location_recognition /other/workspace/perception/location_recognition /other/workspace/perception/location_recognition /other/workspace/perception/location_recognition /other/workspace/perception/location_recognition/CMakeFiles/location_recognition_automoc.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/other/workspace/perception/location_recognition'
make -f CMakeFiles/location_recognition_automoc.dir/build.make CMakeFiles/location_recognition_automoc.dir/build
make[2]: Entering directory `/other/workspace/perception/location_recognition'
/usr/local/bin/cmake -E cmake_progress_report /other/workspace/perception/location_recognition/CMakeFiles 9
[ 11%] Automoc for target location_recognition
/usr/local/bin/cmake -E cmake_automoc /other/workspace/perception/location_recognition/CMakeFiles/location_recognition_automoc.dir/
AUTOMOC: Checking /other/workspace/perception/location_recognition/src/voting_classifier.cpp
AUTOMOC: Checking /other/workspace/perception/location_recognition/src/voting_classifier_helper.cpp
AUTOMOC: Checking /other/workspace/perception/location_recognition/src/results_scene.cpp
AUTOMOC: Checking /other/workspace/perception/location_recognition/src/image_window_widget.cpp
AUTOMOC: Checking /other/workspace/perception/location_recognition/src/image_result_matrix.cpp
AUTOMOC: Checking /other/workspace/perception/location_recognition/src/location_recognition.cpp
AUTOMOC: Checking /other/workspace/perception/location_recognition/src/main.cpp
make[2]: Leaving directory `/other/workspace/perception/location_recognition'
/usr/local/bin/cmake -E cmake_progress_report /other/workspace/perception/location_recognition/CMakeFiles  9
[ 11%] Built target location_recognition_automoc
make -f CMakeFiles/location_recognition.dir/build.make CMakeFiles/location_recognition.dir/depend
make[2]: Entering directory `/other/workspace/perception/location_recognition'
cd /other/workspace/perception/location_recognition && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /other/workspace/perception/location_recognition /other/workspace/perception/location_recognition /other/workspace/perception/location_recognition /other/workspace/perception/location_recognition /other/workspace/perception/location_recognition/CMakeFiles/location_recognition.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/other/workspace/perception/location_recognition'
make -f CMakeFiles/location_recognition.dir/build.make CMakeFiles/location_recognition.dir/build
make[2]: Entering directory `/other/workspace/perception/location_recognition'
/usr/local/bin/cmake -E cmake_progress_report /other/workspace/perception/location_recognition/CMakeFiles 3
[ 22%] Building CXX object CMakeFiles/location_recognition.dir/src/results_scene.cpp.o
/usr/bin/c++   -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -O3 -DNDEBUG -fPIE -I/other/workspace/perception/location_recognition -I/opt/ros/fuerte/include/opencv -I/opt/ros/fuerte/include -I/other/workspace/perception/location_recognition/include -I/other/workspace/perception/location_recognition/ui_forms -I/other/Qt5.0.1/5.0.1/gcc_64/include -I/other/Qt5.0.1/5.0.1/gcc_64/include/QtWidgets -I/other/Qt5.0.1/5.0.1/gcc_64/include/QtGui -I/other/Qt5.0.1/5.0.1/gcc_64/include/QtCore -I/other/Qt5.0.1/5.0.1/gcc_64/mkspecs/linux-g++-64 -I/other/workspace/perception/location_recognition/../perception_kit/utilities/include -I/other/workspace/perception/location_recognition/../perception_kit/visual_categorization/include    -o CMakeFiles/location_recognition.dir/src/results_scene.cpp.o -c /other/workspace/perception/location_recognition/src/results_scene.cpp
In file included from /other/workspace/perception/location_recognition/src/results_scene.cpp:4:0:
/other/workspace/perception/location_recognition/include/perception_kit/location_recognition/results_scene.h:6:29: fatal error: ui_results_view.h: No such file or directory
compilation terminated.
make[2]: *** [CMakeFiles/location_recognition.dir/src/results_scene.cpp.o] Error 1
make[2]: Leaving directory `/other/workspace/perception/location_recognition'
make[1]: *** [CMakeFiles/location_recognition.dir/all] Error 2
make[1]: Leaving directory `/other/workspace/perception/location_recognition'
make: *** [all] Error 2

Tak więc, albo jest w stanie utworzyć nagłówek ui_form, albo nie jest poprawnie linkowany. Spędziłem czas eksperymentując z QT_WRAP_UI i QT5_WRAP_UI, ale nie mogłem rozwiązać problemu. Co powinno się zmienić w moim CMakeLists.txt, aby nagłówki ui_form zostały uwzględnione poprawnie?


16
2018-04-26 21:00


pochodzenie




Odpowiedzi:


Nadużyłeś qt5_wrap_ui makro. Według dokumentacja, ma następujące parametry

qt5_wrap_ui(outfiles inputfile ... OPTIONS ...)

W twoim przykładzie staje się to:

qt5_wrap_ui(UIS_HDRS
    ui_forms/image_result_matrix.ui
    ui_forms/image_window_widget.ui
    ui_forms/location_recognition.ui
    ui_forms/ui_results_view.ui
)

Polecenie skonfiguruje twój projekt do przetwarzania plików * .ui na prawidłowe C ++ ui_XXXX.h i zapisz ich ścieżkę do listy o nazwie UIS_HDRS. Dzięki temu możesz ich użyć jako wejścia celu zadeklarowanego później:

add_executable(location_recognition ${SRC} ${UIS_HDRS})

Uwaga: pliki ui_XXXX.h są generowane w katalogu budowania ${CMAKE_CURRENT_BINARY_DIR}.


21
2018-05-03 13:22



Dzięki ! To pozbyło się problemu .h nie znaleziono problemu. Ale teraz pojawia się problem "vtable not defined" dla niektórych funkcji. Już ustawiłem (CMAKE_AUTOMOC ON). Czy jest coś więcej, co trzeba dodać, np. CMAKE_AUTOMOC dla ui_forms. ? - navderm
@navderm Czy rozwiązałeś ten problem? - Maik Klein
@navderm nvm znalazł odpowiedź stackoverflow.com/questions/19761767/... - Maik Klein