• 275查看
  • 0回复

[应用层软件] VSCode配置调试环境——C/Python

[复制链接]


该用户从未签到

发表于 8-3-2024 21:05:30 | 显示全部楼层 |阅读模式

汽车零部件采购、销售通信录       填写你的培训需求,我们帮你找      招募汽车专业培训老师


新年到了,除了打扫卫生之外,小编把家里的老年机也重做了系统,顺带着安装软件的功夫配置了下常用语言的调试环境。


    Python调试环境


1.1 下载、安装python

Python的官网:Welcome to Python.org,目前最新的版本号已经到了3.12,安装的话比较简单,一路next即可,注意添加 exe到 Path中。

VSCode配置调试环境——C/Pythonw1.jpg

安装完成后简单验证一下,可以在cmd中敲出python,之后import this,就会显示python之禅了。

VSCode配置调试环境——C/Pythonw2.jpg

1.2 VScode环境配置

需要在vscode软件中安装python的扩展插件,

VSCode配置调试环境——C/Pythonw3.jpg

VSCode配置调试环境——C/Pythonw4.jpg

之后我们新建文件,敲完代码之后直接双击F5即可。

VSCode配置调试环境——C/Pythonw5.jpg

或者在终端中使用命令行也可。

VSCode配置调试环境——C/Pythonw6.jpg

VSCode配置调试环境——C/Pythonw7.jpg

2. C语言调试环境

2.1 安装winGW64

下载地址:MinGW-w64 - for 32 and 64 bit Windows - Browse /mingw-w64 at SourceForge.net

VSCode配置调试环境——C/Pythonw8.jpg

下载之后解压。

2.2 修改环境变量

需要将解压后文件的地址放入环境变量中。

VSCode配置调试环境——C/Pythonw9.jpg

之后还是常规的cmd测试。

VSCode配置调试环境——C/Pythonw10.jpg

2.3 配置VSCODE

首先还是安装插件。

VSCode配置调试环境——C/Pythonw11.jpg

VSCode配置调试环境——C/Pythonw12.jpg

之后需要手动建.vscode文件夹,并添加文件以下文件,需要将路径相关修改为之前minGW的解压路径。

c_cpp_properties.json
{"configurations": [        {"name": "Win32","includePath": ["${workspaceRoot}","D:/Environment/install/mingw810_64/include/**","D:/Environment/install/mingw810_64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++","D:/Environment/install/mingw810_64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32","D:/Environment/install/mingw810_64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward","D:/Environment/install/mingw810_64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include","D:/Environment/install/mingw810_64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed","D:/Environment/install/mingw810_64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"            ],"defines": ["_DEBUG","UNICODE","__GNUC__=6","__cdecl=__attribute__((__cdecl__))"            ],"intelliSenseMode": "msvc-x64","browse": {"limitSymbolsToIncludedHeaders": true,"databaseFilename": "","path": ["${workspaceRoot}","D:/Environment/install/mingw810_64/include/**","D:/Environment/install/mingw810_64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++","D:/Environment/install/mingw810_64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32","D:/Environment/install/mingw810_64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward","D:/Environment/install/mingw810_64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include","D:/Environment/install/mingw810_64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed","D:/Environment/install/mingw810_64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"                ]            }        }    ],"version": 4}
launch.json
{"version": "0.2.0","configurations": [        {"name": "g++.exe - 生成和调试活动文件","type": "cppdbg","request": "launch","program": "${fileDirname}\\${fileBasenameNoExtension}.exe","args": [],"stopAtEntry": false,"cwd": "${fileDirname}","environment": [],"externalConsole": false,"MIMode": "gdb","miDebuggerPath": "D:\\Environment\\install\\mingw810_64\\bin\\gdb.exe", //自己电脑中mingw64里面的gdb.exe文件路径"setupCommands": [                {"description": "为 gdb 启用整齐打印","text": "-enable-pretty-printing","ignoreFailures": true                }            ],"preLaunchTask": "C/C++: g++.exe build active file"        }    ]}
tasks.json

{"tasks": [        {"type": "cppbuild","label": "C/C++: g++.exe build active file","command": "D:\\Environment\\install\\mingw810_64\\bin\\g++.exe", //同理 找路径"args": ["-fdiagnostics-color=always","-g","${file}","-o","${fileDirname}\\${fileBasenameNoExtension}.exe"            ],"options": {"cwd": "${fileDirname}"            },"problemMatcher": ["$gcc"            ],"group": {"kind": "build","isDefault": true            },"detail": "调试器生成的任务。"        }    ],"version": "2.0.0"}
2.4 之后也是F5去断点调试即可。

VSCode配置调试环境——C/Pythonw13.jpg

当然,可是可以使用终端的命令来执行。

VSCode配置调试环境——C/Pythonw14.jpg

VSCode配置调试环境——C/Pythonw15.jpg

快速发帖

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|Archiver|汽车工程师之家 ( 渝ICP备18012993号-1 )

GMT+8, 1-2-2025 10:54 , Processed in 0.207800 second(s), 32 queries .

Powered by Discuz! X3.5

© 2001-2013 Comsenz Inc.