win10 64位下 VSCode 配置 C/C++ 开发环境
作者:互联网
1、下载、安装 c/c++编译器
2、下载、安装 vscode
3、vscode内安装c/c++扩展
4、配置c/c++环境
1、我选择的是MinGW编译器,https://sourceforge.net/projects/mingw-w64/files/mingw-w64/
x86_64 和 i686 架构
w64 和 posix 是线程,windows选 w64,linux选posix
最后面是异常模型,我选的seh
win10 64位 选的是 x86_64-win32-seh
下载的 解压
将 \mingw64\bin 加到环境变量中
(注意 选择MinGW-W64-install.exe 后续下载可能会很慢)
2、下载安装vscode。 https://code.visualstudio.com/ 自行根据操作系统选择下载,一路next即可
3、安装好vscode后,Ctrl+Shift+x 打开扩展,搜索 c/c++ 后安装
4、配置c/c++环境
4.1、配置编译器
vscode中 按 Ctrl+Shift+P,在调出的命令面板中 输入 c/c++, 选择 c/c++:编辑配置(UI) 或 c/c++:Edit Configurations(UI) 进入配置
要改两个地方
(1)、编译器路径,改为MinGW解压路径中g++.exe的完整路径
(2)、IntelliSense 模式 改为 gcc-x64
配置完成后,此时在侧边栏可以发现多了一个.vscode文件夹,并且里面有一个c_cpp_properties.json文件,内容如下,说明上述配置成功。现在可以通过Ctrl+<`快捷键打开内置终端并进行编译运行了。
1 { 2 "configurations": [ 3 { 4 "name": "Win32", 5 "includePath": [ 6 "${workspaceFolder}/**" 7 ], 8 "defines": [ 9 "_DEBUG", 10 "UNICODE", 11 "_UNICODE" 12 ], 13 "windowsSdkVersion": "10.0.17763.0", 14 "compilerPath": "E:\\C\\x86_64-8.1.0-release-win32-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe", 15 "cStandard": "c17", 16 "cppStandard": "c++17", 17 "intelliSenseMode": "gcc-x64" 18 } 19 ], 20 "version": 4 21 }
4.2、配置构建任务
Ctrl+Shift+P调出命令面板,输入tasks,选择“Tasks:Configure Default Build Task”:
然后再选择 c/c++:g++.exe build active file
此时会出现一个名为tasks.json的配置文件,内容如下:
1 { 2 "version": "2.0.0", 3 "tasks": [ 4 { 5 "type": "cppbuild", 6 "label": "C/C++: g++.exe build active file", 7 "command": "E:\\C\\x86_64-8.1.0-release-win32-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe", 8 "args": [ 9 "-g", 10 "${file}", 11 "-o", 12 "${fileDirname}\\${fileBasenameNoExtension}.exe" 13 ], 14 "options": { 15 "cwd": "E:\\C\\x86_64-8.1.0-release-win32-seh-rt_v6-rev0\\mingw64\\bin" 16 }, 17 "problemMatcher": [ 18 "$gcc" 19 ], 20 "group": { 21 "kind": "build", 22 "isDefault": true 23 }, 24 "detail": "compiler: E:\\C\\x86_64-8.1.0-release-win32-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe" 25 } 26 ] 27 }
4.3、配置调试设置
点击菜单栏的Debug-->Start Debugging:
vscode会新建 launch.json文件,preLaunchTask 要填上一步task.json的label的内容,miDebuggerPath 要填写 MinGW解压路径中gdb.exe的完整路径
1 { 2 // Use IntelliSense to learn about possible attributes. 3 // Hover to view descriptions of existing attributes. 4 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 "version": "0.2.0", 6 "configurations": [ 7 { 8 "name": "(gdb) 启动", 9 "preLaunchTask": "C/C++: g++.exe build active file", 10 "type": "cppdbg", 11 "request": "launch", 12 "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", 13 "args": [], 14 "stopAtEntry": false, 15 "cwd": "${workspaceFolder}", 16 "environment": [], 17 "externalConsole": false, 18 "MIMode": "gdb", 19 "miDebuggerPath": "E:\\C\\x86_64-8.1.0-release-win32-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe", 20 "setupCommands": [ 21 { 22 "description": "为 gdb 启用整齐打印", 23 "text": "-enable-pretty-printing", 24 "ignoreFailures": true 25 } 26 ] 27 } 28 ] 29 }
以上 配置完成
以下测试
新建main.c文件,写入以下内容,按F5运行。
1 #include <stdio.h> 2 #include <time.h> 3 4 #define BST (+1) 5 #define CCT (+8) 6 7 int main () 8 { 9 10 time_t rawtime; 11 struct tm *info; 12 13 time(&rawtime); 14 /* 获取 GMT 时间 */ 15 info = gmtime(&rawtime ); 16 17 printf("当前的世界时钟:\n"); 18 printf("伦敦:%2d:%02d\n", (info->tm_hour+BST)%24, info->tm_min); 19 printf("中国:%2d:%02d\n", (info->tm_hour+CCT)%24, info->tm_min); 20 21 return(0); 22 }
结果如下图
标签:exe,x86,VSCode,c++,++.,64,C++,seh 来源: https://www.cnblogs.com/youjiao/p/14064216.html