赞
踩
pacman -S mingw-w64-x86_64-toolchain
pacman -S mingw-w64-x86_64-cmake
toolchain包中包含很多不必要的工具包,应该可以指定具体的工具g++,gcc,mingw32-make的下载,详细命令请自行搜索。
msys2项目中会有几种不同的编译工具clang,mingw,ucrt这里只需要将你想用的工具集的bin目录添加即可
cmake --version
g++ -v
gcc -v
mingw32-make -v
总的来说就只有两条核心命令
cmake -S . -B build -G MinGW Makefiles
-S 指定CMakeLists.txt与执行命令目录的相对路径
-B 中间文件的生成目录
-G 指定生成器,常用的有MinGW Makefiles, Ninja,Visual Studio 16 2019等
cmake --build build
根据生成的中间文件构建可执行文件
对于vscode不下载插件且能很方便的使用cmake功能主要是依靠tasks.json与lanuch.json文件。编写tasks.json文件后,点击终端->运行任务->选择想要执行的任务。
{ "version": "2.0.0", "options": { "cwd": "${workspaceFolder}/build/" // "cwd": "${workspaceFolder}/" }, "tasks": [ { "label": "cmake", "type": "shell", "command": "cmake", "args": [ "..", "-G", "MinGW Makefiles" ] }, { "label": "make", "group":{ "kind":"build", "isDefault":true }, // "command":"mingw32-make.exe", // "command":"ninja", "command":"cmake", "args":[ "--build" , "." ] }, { "label":"Build my project", "dependsOn":[ "cmake", "make" ] } ] }
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) 启动", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}\\build\\testfile.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "externalConsole": true, "MIMode": "gdb", // "miDebuggerPath": "D:/MinGW64/bin/gdb.exe", "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe", "setupCommands": [ { "description": "为 gdb 启用整齐打印", "text": "-enable-pretty-printing", "ignoreFailures": true }, { "description": "将反汇编风格设置为 Intel", "text": "-gdb-set disassembly-flavor intel", "ignoreFailures": true } ], "preLaunchTask": "Build my project" } ] }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。