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写在了一起,当我分开之后就没有这个问题

相关推荐
clint4561 天前
C++进阶(1)——前景提要
c++
夜悊1 天前
C++代码示例:进制数简单生成工具
c++
郝学胜_神的一滴1 天前
CMake 021: IF 条件判据详诠
c++·cmake
_wyt0012 天前
洛谷 B3930 [GESP202312 五级] 烹饪问题 题解
c++·gesp
LDR0062 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术2 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript
码云数智-园园2 天前
C++20 Modules 模块详解
java·开发语言·spring
swordbob2 天前
NIO的channel中什么是 fd(File Descriptor,文件描述符)
java·开发语言·nio
源分享2 天前
Java线程同步的多种实现方法(非常详细)
java·开发语言·jvm
Luminous.2 天前
C语言--day30
c语言·开发语言