vscode——详细总结篇、简单易懂debug,
vscode——详细总结篇、简单易懂debug,
一、先来个demo
文件夹debug_vs下,只有一个mian.cpp,一个cmakelists.txt,然后进行外部构建建立一个build文件夹存放临时文件。
以上是cmakeLists.txt文本文件,注意第三行的设置为debug模式(在这里如果不设置,出现无法调试,直接执行结束)
launch.json文件是用来进行运行配置的
这里需要修改两处,12line设置为可执行文件路径+可执行文件名,另外17line一定要修改为false,否则无法调试如下:
解决办法:https://github.com/Microsoft/vscode-cpptools/issues/2922
使用F5或者点击左侧菜单栏倒数第二个虫子,debug
二、知识点
2.1CMakeLists.txt设置dubug模式:http://www.cnblogs.com/lidabo/p/7359422.html
2.2常见的json变量
https://blog.csdn.net/u010677365/article/details/80703984
https://blog.csdn.net/bailsong/article/details/77527773
${workspaceFolder} - the path of the folder opened in VS Code
${workspaceRootFolderName} - the name of the folder opened in VS Code without any slashes (/)
${file} - the current opened file
${relativeFile} - the current opened file relative to workspaceRoot
${fileBasename} - the current opened file’s basename
${fileBasenameNoExtension} - the current opened file’s basename with no file extension
${fileDirname} - the current opened file’s dirname
${fileExtname} - the current opened file’s extension
${cwd} - the task runner’s current working directory on startup
${lineNumber} - the current selected line number in the active file
${env:Path} - environment variables reference path
2.3vscode插件
其中C/C++为必装,提供C/C++支持
Code Runner必装,提供编译后程序的运行环境
C/C++ Snippets建议 提供一些常用的C/C++片段,如for(;;){},安装后写代码方便(tip.如果想要添加自己写的代码段可以点左下角齿轮->用户代码片段)
EPITECH C/C++ Headers 为C/C++文件添加头部(包括作者、创建和修改日期等),并为.h头文件添加防重复的宏
File Templates 文件模板,可以自己添加文件模板
GBKtoUTF8 GBK编码文件转换为UTF-8
Include Autocomplete 头文件自动补全
One Dark Pro 一个好看的vscode主题
Easy C++ projects提供一个简单的编译模式,开启后只要安装了C/C++扩展就可以直接编译运行,建议不用,因为不能自己配置参数
2.4 vscode 环境配置
这里的环境是设置vscode的运行环境,通过*.json
文件来设置。
一旦生成了json文件,vscode就会在项目文件夹内生成一个隐藏的.vscode
文件夹,其中包含所有产生的json文件。
按ctrl + shift + P
打开vscode控制台(记住此快捷键,以后经常用),输入C/Cpp: Edit configurations
,就自动生成了一个c_cpp_properties.json
文件,这样你就可以在该文件中编写参数来调整设置。
c_cpp_properties.json文件主要是设置系统级的大环境,基本上不用改(除非有第三方库,后面会说)
settings.json
ctrl+shift+p打开vscode终端,输入setting,选择下拉选项中带“json”的。打开的settings.json文件如图所示,左侧是系统默认的配置项,右侧是用户自定义的设置,自定义的设置项会覆盖系统默认的配置项
还有一个task.json是用于编译的,也可以选择cmake-tools插件编译。
参考:
ubuntu系统下使用vscode 编译调试c++程序,添加外部库:
https://blog.csdn.net/u010677365/article/details/80703984
vscode_插件开发攻略
https://www.cnblogs.com/liuxianan/p/vscode-plugin-overview.html
相关文章
- 暂无相关文章
用户点评