c++ - CMake Automoc 错误 1 ​​- 无法编译项目

标签 c++ qt cmake qt5 moc

我刚刚将我在 Qt5 中构建的项目移到了我的 CMake 项目树中。 我将项目导出到 CMake 目录中。但是,当我尝试构建项目时,编译器会给我以下错误: [src/GUIconceptStudy/CMakeFiles/GUIconceptStudy_automoc] 错误 1

另请参阅以下附加的打印屏幕: Automoc Error 1

下面还有 CMakeLists.txt 文件:

cmake_minimum_required (VERSION 3.1)
project(GUIconceptStudy)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

find_package( OpenCV REQUIRED )
find_package( Boost COMPONENTS system thread filesystem REQUIRED)

#find_package (sqlite3)
find_package(Qt5 REQUIRED COMPONENTS Core Quick)

###
### make sure we use c++11
###
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

###
###boost include stuff (required for all libcam)
###
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )

find_package(Qt5Widgets)
find_package(Qt5PrintSupport)
#find all the qt UI stuff
file(GLOB UI
    "ui/*.ui"
)

#make them into headers
qt5_wrap_ui (UI_HDRS  ${UI})

###
### add all your non QT sources
###

# find all non ui sources
file(GLOB SRCS
    "src/*.h"
    "src/*.cpp"
    "src/*.hpp"
)

# find all ui related sources
file(GLOB UI_SRCS
    "ui/*.h"
    "ui/*.cpp"
    "ui/*.hpp"
)

###
### Add executables
###
add_executable(GUIconceptStudy main/main.cpp ui/qrc/res.qrc ${SRCS} ${UI_HDRS} ${UI_SRCS})
target_link_libraries (GUIconceptStudy  Qt5::Widgets  ${Boost_LIBRARIES} ${OpenCV_LIBS} Qt5::PrintSupport Qt5::Core Qt5::Quick)

###
### Add Library
###
add_library(GUIconceptStudy_lib SHARED ui/qrc/res.qrc ${SRCS} ${UI_HDRS} ${UI_SRCS})
target_link_libraries (GUIconceptStudy_lib Qt5::Widgets  ${Boost_LIBRARIES} ${OpenCV_LIBS} Qt5::PrintSupport Qt5::Core Qt5::Quick)

在查看了不同的在线资源后,我找不到任何特别有用的东西。任何人都可以阐明问题所在吗?

最佳答案

这是在黑暗中拍摄的,但这很可能是由于缺少 set(CMAKE_INCLUDE_CURRENT_DIR ON) 造成的。正如documentation中所说它应该设置,因为生成的文件不在您的源目录中:

Generated moc_*.cpp and *.moc files are placed in the build directory so it is convenient to set the CMAKE_INCLUDE_CURRENT_DIR variable.

我看到人们犯的另一个错误是混合使用 Qt 处理管道。我已经在我的其他 answers 中提到过这个.正如关于 AUTOUIC property 的文档中所说启用此属性时,您不应使用 qt5_wrap_ui 函数。

关于c++ - CMake Automoc 错误 1 ​​- 无法编译项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50725670/

相关文章:

c++ - C++ 二进制代码能否通过 native C 接口(interface)变得可移植?有什么限制?

C++ shared_ptr std::bind 和 std::function

python - QT 的奇怪 Python 线程问题

python - 如何在 PyQt5 中向 QLabel 添加信号?

c++ - 将多个 QTimers 调用排队到插槽

c++ - 安装 BLAS 时遇到问题,以及 CMakeLists 的用途?

B 树的自定义迭代器中的运算符 * 出现 C++ 错误

c++ - 是否需要将空指针分配给 std::auto_ptr

c++ - Python.h : No such file or directory

c++ - NDK 问题 : crash on 32bit, 在 64 位上不一致