CMake& QT5-QT5_WRAP_UI不生成ui头文件 [英] CMake & QT5 - QT5_WRAP_UI not generating ui header files

查看:1063
本文介绍了CMake& QT5-QT5_WRAP_UI不生成ui头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的CMakeLists.txt,看起来像这样:

I have a simple CMakeLists.txt that looks like this:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT(calculator)

FIND_PACKAGE(Qt5Core)
FIND_PACKAGE(Qt5Gui)
FIND_PACKAGE(Qt5Widgets)

SET(CMAKE_AUTOMOC ON)
SET(CMAKE_INCLUDE_CURRENT_DIR ON)

SET(calculator_SOURCES main.cpp mainwindow.cpp)
SET(calculator_HEADERS mainwindow.h)
SET(calculator_FORMS mainwindow.ui)

QT5_WRAP_CPP(calculator_HEADERS_MOC ${calculator_HEADERS})
QT5_WRAP_UI(calculator_FORMS_HEADERS ${calculator_FORMS})

ADD_LIBRARY(calculator_CONFIG ${calculator_HEADERS_MOC} ${calculator_FORMS_HEADERS})
QT5_USE_MODULES(calculator_CONFIG Widgets)

ADD_EXECUTABLE(calculator ${calculator_SOURCES} ${calculator_CONFIG})
QT5_USE_MODULES(calculator Core Gui Widgets)

当我尝试使用cmake -G "Unix Makefiles"和随后的make生成项目时,控制台会显示未找到ui_mainwindow.h.问题是什么?是我的cmake文件吗?

And when I try to build the project using cmake -G "Unix Makefiles" and subsequently make, the console says that ui_mainwindow.h is not found. What is the problem? Is it my cmake file?

完整错误输出:

[ 22%] Building CXX object CMakeFiles/calculator.dir/mainwindow.cpp.o
/home/centurion/Code/cpp/calculator/mainwindow.cpp:2:27: fatal error: ui_mainwindow.h: No such file or directory
 #include "ui_mainwindow.h"
                           ^
compilation terminated.
make[2]: *** [CMakeFiles/calculator.dir/mainwindow.cpp.o] Error 1
make[1]: *** [CMakeFiles/calculator.dir/all] Error 2
make: *** [all] Error 2

推荐答案

  1. 使用小写的CMake命令.多年来一直是理智的惯例.

  1. Use lower-case CMake commands. That has been the sane convention for years.

为什么同时使用AUTOMOCqt5_wrap_cpp? AUTOMOC旨在替换宏. http://www.cmake. org/cmake/help/v3.0/manual/cmake-qt.7.html#automoc

Why are you using both AUTOMOC and qt5_wrap_cpp? AUTOMOC is designed to replace the macro. http://www.cmake.org/cmake/help/v3.0/manual/cmake-qt.7.html#automoc

如果使用CMake 2.8.11或更高版本,则不要使用qt5_use_modules.直到发布CMake 2.8.11之前,我都将其写为权宜之计. target_link_libraries命令可以执行qt5_use_modules的功能,但是效果更好,更通用. http://doc-snapshot.qt-project.org/qt5-5.3/cmake-manual.html

If using CMake 2.8.11 or later, then don't use qt5_use_modules. I wrote that as a stop-gap hack until CMake 2.8.11 was released. The target_link_libraries command does what qt5_use_modules does, but better and more-generically. http://doc-snapshot.qt-project.org/qt5-5.3/cmake-manual.html

该库没有自己的资源,因此无法使用.您显然在这里做错了".将${calculator_FORMS_HEADERS}变量用法移至可执行文件源.然后,在指向第2点之后,删除该库.

The library has no sources of its own and is not used. You're clearly 'doing it wrong' here. Move the ${calculator_FORMS_HEADERS} variable usage to the executables sources. Then after addressing point 2, remove the library.

这篇关于CMake& QT5-QT5_WRAP_UI不生成ui头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆