gpt4 book ai didi

cmake - 无法在 cmake 中包含 QT5 的 ui_form header

转载 作者:行者123 更新时间:2023-12-03 14:49:07 25 4
gpt4 key购买 nike

我的 CMakeLists.txt 看起来像:

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)

当我做
cmake .

它很好。但是当我尝试 make它仍然说未找到 ui_forms/*.h header 并且它失败了。

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[1]: * [CMakeFiles/location_recognition.dir/all] Error 2 make: * [all] Error 2



当我执行“使 VERBOSE=1”
我明白了
/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

因此,不知何故,它要么能够创建 ui_form header ,要么无法正确链接。
我花了很长时间试验 QT_WRAP_UI 和 QT5_WRAP_UI 但无法解决问题。
为了正确包含 ui_form header ,我的 CMakeLists.txt 应该进行哪些更改?

最佳答案

你误用了qt5_wrap_ui宏。根据the documentation , 它有以下参数

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

在您的示例中,这变为:
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
)

该命令将配置您的项目以将 *.ui 文件处理为有效的 C++ ui_XXXX.h并将他们的路径保存到名为 UIS_HDRS 的列表中.这允许您将它们用作稍后声明的目标的输入:
add_executable(location_recognition ${SRC} ${UIS_HDRS})

注意:ui_XXXX.h文件在build目录下生成 ${CMAKE_CURRENT_BINARY_DIR} .

关于cmake - 无法在 cmake 中包含 QT5 的 ui_form header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16245147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com