博客
关于我
vscode配置C++开发环境
阅读量:167 次
发布时间:2019-02-28

本文共 1380 字,大约阅读时间需要 4 分钟。

昨天一直研究到深夜,查阅了很多博客资料,还是没配置好VSCode的C++编译环境,今天早上又弄了一下,现在终于OK了。

虽然很多东西的原理不太明白,但现在至少知道了基本方法,以后多练习应该会慢慢熟悉起来。

第一步,先去VSCode官网下载安装,安装到自己想要的位置就可以了。

第二步,去MinGW官网下载安装,同样可以安装到自己想要的位置。

下载时注意不要点击"Download Latest Version",而是往下滑找到最新版的"x86_64-posix-seh"进行下载。

第三步,配置MinGW环境变量。

第一步,复制MinGW路径(具体路径请参考第六点)。第二步,打开控制面板,搜索高级系统设置,进入系统环境变量。第三步,点击环境变量。第四步,双击Path选项。第五步,点击新建。第六步,将MinGW的安装路径粘贴进去。第七步,退出所有窗口。

到现在MinGW环境已经配置完毕,可以验证一下是否成功:按下Win+R,打开运行窗口,输入cmd。输入g++,如果有两种反馈:第一种:环境配置成功。第二种:环境配置失败,提示"'g++'不是内部或外部命令"。

第四步,打开VSCode,点击扩展,先下载一个中文包。接着在扩展里搜索C/C++插件,下载相应的插件。

第六步,在自己想要的位置新建一个code_test文件夹,打开VSCode,选择这个文件夹。在code_test中新建一个test.cpp文件。在test.cpp中输入一份简易测试代码:

#include <stdio.h>#include <windows.h>int main() {printf("Hello VScode!\nHello C++\n");system("pause");return 0;}</windows.h></stdio.h>

按下Ctrl+F5,选择C++(GDB/LLDB),再选择g++.exe。

完成上述操作后,会生成launch.json文件,粘贴以下代码:

{"version": "0.2.0","configurations": [{"name": "g++.exe - 生成和调试活动文件","type": "cppdbg","request": "launch","program": "${fileDirname}\${fileBasenameNoExtension}.exe","args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": true,"MIMode": "gdb","miDebuggerPath": "D:\2Software\mingw64\bin\gdb.exe","setupCommands": [{"description": "为gdb启用整齐打印","text": "-enable-pretty-printing","ignoreFailures": true}],"preLaunchTask": "g++.exe build active file"}]}

回到test.cpp文件,按下Ctrl+F5,选择配置任务,完成后按下Ctrl+F5就可以正常编译运行了。

转载地址:http://ueod.baihongyu.com/

你可能感兴趣的文章
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>
no1
查看>>