vscode使用wsl(ubuntu)编译调试样例,使用mingw编译调试样例
1.安装vscode及插件如下
可以参考使用WSL+VSCode快速C++入门_wsl c++ setting.json_逗神大人的博客-CSDN博客
2.安装wsl和mingw
mingw从官方下载较慢,可以从下面下载
https://download.csdn.net/download/qjm1995/11094533
3.使用wsl编译和调试
配置文件详细如下:
c_cpp_properties.json
{
"configurations": [{
"name": "WSL",
"intelliSenseMode": "gcc-x64",
"compilerPath": "/usr/bin/g++",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"cStandard": "c11",
"cppStandard": "c++17"
}],
"version": 4
}
launch.json
{
"version": "0.2.0",
"configurations": [{
"name": "hello Launch",
"type": "cppdbg",
"request": "launch",
"program": "/mnt/d/vscode_work/wsl_hello/hello",
"args": [],
"stopAtEntry": false,
"cwd": "/mnt/d/vscode_work/wsl_hello",
"environment": [],
"externalConsole": true,
"windows": {
"MIMode": "gdb",
"setupCommands": [{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}]
},
"pipeTransport": {
"pipeCwd": "",
"pipeProgram": "c:\\windows\\sysnative\\bash.exe",
"pipeArgs": ["-c"],
"debuggerPath": "/usr/bin/gdb",
},
"sourceFileMap": {
"/mnt/d": "d:\\"
}
}]
}
settings.json
{
"terminal.external.windowsExec": "C:\\WINDOWS\\System32\\bash.exe",
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\bash.exe"
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"optional": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp",
"functional": "cpp",
"iterator": "cpp",
"numeric": "cpp"
}
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "process",
"command": "bash.exe",
"args": [
"-c",
"scons"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
}
]
}
SConstruct
env=Environment(CCFLAGS = ['-g','-std=c++11','-Wall'])
env.Program('hello', Glob('*.cpp'), LIBS = ['m'], LIBPATH = ['/usr/lib'])
4.使用mingw编译和调试
配置文件详细如下:
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}",
"D:\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include\\c++"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:\\MinGW\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "hello Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/hello.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build hello"
}
]
}
settings.json
{
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"optional": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp",
"functional": "cpp",
"iterator": "cpp",
"numeric": "cpp"
}
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build hello",
"type": "shell",
"command": "g++",
"args": [
"*.cpp",
"-g",
"-o",
"hello.exe",
"-std=c++11",
"-Wall",
"-lm",
"-L.",
"-I."
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
}
]
}
PS: