如果项目完全是 C++,应该没有理由离开 WSL。构建和启动应用程序可以在这里轻松处理!
您完全可以使用
在 bash 中通过命令行构建
g++ -o <outputfile> <inputfiles>
但是,运行程序最简单的方法是在 Visual Code 中创建构建配置。您将需要 2 个文件:launch.json 和 tasks.json
要创建启动文件,请按 F1(或打开命令托盘)并选择任务:配置默认构建任务。它应该看起来像这样。
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}", //input files
"-o",
"${fileDirname}/a.out" //output file
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
要创建launch.json,请转到“调试”选项卡并选择“创建launch.json 文件”。它应该看起来像这样
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/a.out", //output file
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
有了这两个文件,您所要做的就是像在 Visual Studio 中一样点击运行按钮。