最近帮GF(不幸变成ex了)配置C++开发环境,一开始想给她装个visual studio13完事,可是一想到本身安装以及使用时的诸多麻烦,就有点退却,以为没有这个必要。正好了解到vscode大行其道,决定按照官网指示配置一版。因为本人非计算机科班出身,对编译原理了解很少,在配置环境的时候遇到了一些麻烦,参照网上的诸多教程,最后发现仍是官网比较靠谱,因此结合本身配置的教训,写个帖子,但愿可以帮到你们。 html
下载网址连接以下。c++
https://code.visualstudio.com/
直接下载安装便可。shell
1)shift + ctrl + P,打开命令行。编程
2)在输入框中输入“Configure Display Language”,点击打开locale.json.json
3) 编辑locale.json文件,如图所示。“locale”: "zh-CN"保存,而后从新打开编辑器便可。windows
1)C/C++dom
2)C++ Intellisense编辑器
3) Chinese(Simplified)中文简体 ui
选择安装tdm64-gcc-5.1.0-2.exe,下载网址连接以下。编码
https://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/tdm64-gcc-5.1.0-2.exe/download
若上述网址失效,进入http://tdm-gcc.tdragon.net/download,选第二个。 建议直接装在C盘,能够减小后面修改路径的麻烦。 安装的时候,须要手动勾选以下图所示的选项(gdb),不然下面5中launch.json "
"miDebuggerPath": "C:/TDM-GCC-64/bin/gdb64.exe"
会出错。
配置四个.json文件,参考官方作法
https://code.visualstudio.com/docs/languages/cpp
须要对miDebuggerPath进行修改,修改成 :
"miDebuggerPath": "C:/TDM-GCC-64/bin/gdb64.exe"
修改完,launch.json长这样,能够直接将这部份内容复制到读者对应的文件中。
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "C:/TDM-GCC-64/bin/gdb64.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "build" } ] }
“includePath”:[ "${workspaceFolder}/**", "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++", "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/x86_64-w64-mingw32", "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/backward", "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include", "C:/TDM-GCC-64/x86_64-w64-mingw32/include", "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include-fixed" ]
和
"compilerPath": "C:/TDM-GCC-64/bin/g++.exe"
修改完,c_cpp_properties.json的内容大概以下,里边能够添加本身调用的外部连接库的路径。
{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**", "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++", "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/x86_64-w64-mingw32", "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/backward", "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include", "C:/TDM-GCC-64/x86_64-w64-mingw32/include", "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include-fixed", "D:/Random/include" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "windowsSdkVersion": "8.1", "compilerPath": "C:/TDM-GCC-64/bin/g++.exe", "cStandard": "c11", "cppStandard": "c++11", "intelliSenseMode": "msvc-x64" } ], "version": 4 }
"command": "g++"
和
"args":[ "-g" ,"${fileBasename}", "-fexec-charset=GBK", //Console窗体输出字符编码 保证能正常显示中文 "-finput-charset=UTF-8" //输入编译器文本编码 默认为UTF-8 ]
为了保证能使用C++的新特性,添加以下语句至"args":
"-std=c++17", // 使用最新的c++17标准
为了可以在其余机器上跑,添加以下语句至"args":
"-static-libgcc", // 静态连接
修改完后,大概长这样。
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build", "type": "shell", "command": "g++", "args":[ "-g" ,"${workspaceFolder}/${fileBasename}", "-I", "D:/Random/include", // 编译时用到的外部库的地址 "-o", "${workspaceFolder}/${fileBasenameNoExtension}.exe", // 指定输出文件名,不加该参数则默认输出a.exe "-ggdb3", // 生成和调试有关的信息 "-Wall", // 开启额外警告 "-static-libgcc", // 静态连接 "-std=c++11", // 使用最新的c++17标准 "-Wno-format", "-fexec-charset=GBK", //Console窗体输出字符编码 保证能正常显示中文 "-finput-charset=UTF-8" //输入编译器文本编码 默认为UTF-8 ], "group": { "kind": "build", "isDefault": true } } ] }
https://www.cnblogs.com/ghjnwk/p/10415294.html