gpt4 book ai didi

c++ - 使用 cmake 构建 Qt5 项目

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:11:31 31 4
gpt4 key购买 nike

我正在尝试使用 cmake 构建一个 Qt5 项目,这是我的 cmake 代码(VS2013 作为生成器):

cmake_minimum_required (VERSION 2.6 FATAL_ERROR)

project (pcl-visualizer)
set(CMAKE_PREFIX_PATH "C:\\Qt2013\\5.7\\msvc2013_64")
set(VTK_DIR "C:\\Program Files\\PCL 1.8.0\\3rdParty\\VTK\\lib\\cmake\\vtk-7.0")
find_package(Qt5Widgets)
find_package (VTK REQUIRED)
find_package (PCL 1.8 REQUIRED)

include_directories (${PCL_INCLUDE_DIRS})
link_directories (${PCL_LIBRARY_DIRS})
add_definitions (${PCL_DEFINITIONS})

include_directories(${Qt5Widgets_INCLUDES})
add_definitions(${Qt5Widgets_DEFINITIONS})
set(CMAKE_CXX_FLAGS "${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
ADD_DEFINITIONS (${QT_DEFINITIONS})

set (project_SOURCES main.cpp pclviewer.cpp)
set (project_HEADERS pclviewer.h)
set (project_FORMS pclviewer.ui)
set (VTK_LIBRARIES vtkRendering vtkGraphics vtkHybrid QVTK)

ADD_DEFINITIONS (${QT_DEFINITIONS})

ADD_EXECUTABLE (pcl_visualizer ${project_SOURCES}
${project_FORMS_HEADERS}
${project_HEADERS_MOC})

TARGET_LINK_LIBRARIES (pcl_visualizer ${QT_LIBRARIES} ${PCL_LIBRARIES} ${VTK_LIBRARIES})

它配置并生成。

-- Configuring done -- Generating done -- Build files have been written to: C:/ysong/pcl/doc/tutorials/content/sources/qt_visualizer/build 10:40:24: Le processus "C:\Program Files\CMake\bin\cmake.exe" s'est terminé normalement. 10:40:24: Impossible de trouver un Makefile. Vérifiez vos options de compilation. Erreur lors de la compilation/déploiement du projet pcl_visualizer (kit : Desktop Qt 5.6.1 MSVC2013 64bit2) When executing step "Make" 10:40:24: Temps écoulé : 00:01.

但项目没有建立(没有ui_pclviewer.h)。我应该怎么做才能完整地构建我的项目。

最佳答案

喜欢 this post ,您的 CMake 文件首先需要清理。

cmake_minimum_required (VERSION 2.6 FATAL_ERROR)

2.6 太旧了,我很确定你真的不需要与旧版本兼容那么远。至少使用 2.8.11

set(CMAKE_PREFIX_PATH "C:\\Qt2013\\5.7\\msvc2013_64")

避免在你的路径中使用“\”,迟早你会遇到麻烦。使用“/”代替,即使在 Windows 上也是如此:

set(CMAKE_PREFIX_PATH "C:/Qt2013/5.7/msvc2013_64")

您也可以设置 Qt5_DIR 而不是 CMAKE_PREFIX_PATH,就像您为 vtk 所做的那样。

不要用以下方法一一查找每个 Qt 模块:

find_package(Qt5Widgets)
find_package(Qt5Gui)
find_package(Qt5Core)

一键添加:

find_package(Qt5 REQUIRED Widgets)

Widgets 就足够了,因为 Qt 的包文件处理依赖项。添加 REQUIRED 以确保找到包。

使用 imported targetsAUTOMOCAUTOUIC,您的 cmake 项目应该如下所示:

cmake_minimum_required(VERSION 2.8.11)

project(pcl-visualizer)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(Qt5_DIR "C:/Qt2013/5.7/msvc2013_64/lib/cmake/Qt5")
set(VTK_DIR "C:/Program Files/PCL 1.8.0/3rdParty/VTK/lib/cmake/vtk-7.0")
find_package(Qt5 REQUIRED Widgets)
find_package (VTK REQUIRED)
find_package (PCL 1.8 REQUIRED)

include_directories (${PCL_INCLUDE_DIRS})
link_directories (${PCL_LIBRARY_DIRS})
add_definitions (${PCL_DEFINITIONS})

set (project_SOURCES main.cpp pclviewer.cpp)
set (project_HEADERS pclviewer.h)
set (project_FORMS pclviewer.ui)
set (VTK_LIBRARIES vtkRendering vtkGraphics vtkHybrid QVTK)

add_executable(pcl_visualizer ${project_SOURCES}
${project_FORMS}
${project_HEADERS})

target_link_libraries(pcl_visualizer Qt5::Widgets ${PCL_LIBRARIES} ${VTK_LIBRARIES})

关于c++ - 使用 cmake 构建 Qt5 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40628811/

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