最近幫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