c++ cmake qt

该技术栈的部署过程分三步:

构建---编译---运行

构建:

bash 复制代码
cmake -S . -B build -G "Visual Studio 16 2019" -A x64 -DCMAKE_PREFIX_PATH="D:\Qt5_15\5.15.2\msvc2019_64\lib\cmake"

编译:

bash 复制代码
cmake --build build --config Debug
bash 复制代码
cmake --build build --config Release

运行:

bash 复制代码
.\build\Debug\QtSnake.exe

或者在文件夹中找的exe文件进行运行。

其中遇到的问题:

bash 复制代码
Automatic MOC for target QtSnake
  
  AutoMoc error
  -------------
  "SRC:/model.cpp"
  contains a "Q_OBJECT" macro, but does not include "model.moc"!
  Consider to
    - add #include "model.moc"
    - enable SKIP_AUTOMOC for this file

D:\Microsoft Viusal 2019\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(145,5): error MSB3073: 命令"setl
ocal [D:\code\QT\Qt_demo\build\QtSnake.vcxproj]
D:\Microsoft Viusal 2019\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(145,5): error MSB3073: cd D:\c 
ode\QT\Qt_demo\build [D:\code\QT\Qt_demo\build\QtSnake.vcxproj]
D:\Microsoft Viusal 2019\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(145,5): error MSB3073: if %err 
orlevel% neq 0 goto :cmEnd [D:\code\QT\Qt_demo\build\QtSnake.vcxproj]
D:\Microsoft Viusal 2019\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(145,5): error MSB3073: D: [D:\ 
code\QT\Qt_demo\build\QtSnake.vcxproj]
D:\Microsoft Viusal 2019\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(145,5): error MSB3073: if %err 
orlevel% neq 0 goto :cmEnd [D:\code\QT\Qt_demo\build\QtSnake.vcxproj]
D:\Microsoft Viusal 2019\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(145,5): error MSB3073: D:\CMak 
e\bin\cmake.exe -E cmake_autogen D:/code/QT/Qt_demo/build/CMakeFiles/QtSnake_autogen.dir/AutogenInfo.json Rel 
ease [D:\code\QT\Qt_demo\build\QtSnake.vcxproj]
D:\Microsoft Viusal 2019\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(145,5): error MSB3073: if %err
orlevel% neq 0 goto :cmEnd [D:\code\QT\Qt_demo\build\QtSnake.vcxproj]
D:\Microsoft Viusal 2019\MSBuild\Microsoft\

我在CMakeLists.txt 中配置了set(CMAKE_AUTOMOC ON) ,按道理mod工具会自动去链接mod文件,但是却没有构建成功。

解决:原因是我将.cpp .h .main写在了一起,当我分开之后就没有这个问题

相关推荐
肆忆_8 小时前
# 用 5 个问题学懂 C++ 虚函数(入门级)
c++
不想写代码的星星12 小时前
虚函数表:C++ 多态背后的那个男人
c++
端平入洛2 天前
delete又未完全delete
c++
端平入洛3 天前
auto有时不auto
c++
郑州光合科技余经理4 天前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
feifeigo1234 天前
matlab画图工具
开发语言·matlab
dustcell.4 天前
haproxy七层代理
java·开发语言·前端
norlan_jame4 天前
C-PHY与D-PHY差异
c语言·开发语言
哇哈哈20214 天前
信号量和信号
linux·c++
多恩Stone4 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc