Main text
Lazy version you can download directly without doing it yourself, password QRSJ
VSCode
* LLVM * mingw64
Be sure to download the compressed archive (.zip) format.
No need to select the sig file
Be sure to choose “Pre-Built Binaries”, and the system bitness must match the one you chose above!
If your system is x64, download x86_64-posix-seh.
If your system is x32, download x86_64-win32-seh.
- Extract VSCode somewhere, then extract MinGW into the VSCode directory
The reason I do these next steps is just to get the LLVM directory. I uninstall it only because I don’t want too many items in the program list. If you’re not obsessive about that, you can skip steps 2-4 and just choose the first folder as the installation directory.
-
Install LLVM, install it anywhere for now
-
Copy the entire LLVM directory into the directory from step 1
-
Uninstall the LLVM from your system
-
Copy
!start.vbsandstart.batfrom the appendix into the folder from step 1 -
Comment out the last line of start.bat i.e. add :: before the last line
-
!!Don’t close the window after this step!! In cmd (or PowerShell), run the script with
.\start.bat, then type clang and gcc. If you get “xxx is not recognized as an internal or external command”, it means your start.bat configuration has a problem. -
In the folder from step 1, create folders with the following names:
UsersUsers\AppDataUsers\AppData\LocalUsers\AppData\RoamingUsers\AppData\Desktop
extensions- Install extensions
Chinese(简中语言包)C/C++vscode-clangdCode RunnerBracket Pair Colorizer 2One Dark Pro(主题包,可选)-
In the cmd (or PowerShell) from step 7, type
.\code.exeto launch VSCode -
Create a new directory in the file explorer (I just created a folder named !Code in the step 1 directory), open it in VSCode, then choose “Save Workspace As”
Note that you should put each language’s working directory in a separate folder, e.g. put C in the c folder and C++ in the c++ folder
-
Create a new folder named C++ inside !Code (adjust based on your own situation)
-
Create a
.vscodefolder in the C++ directory, then copylaunch.json,tasks.json,settings.json, andcompile_flags.txtfrom the appendix into it -
Uncomment the line from step 6, close this VSCode, and run
!start.vbs -
Create a new file and type in some test code
#include <iostream>using namespace std;int main (){ string a=""; cout << "Input:" << endl; cin >> a; cout << a; return 0;}-
Click the arrow in the top right, and see if the console outputs
Input:. Then type something and see if it’s echoed back unchanged -
That’s it
Appendix
start.bat
set ThisDir=%~dp0set USERPROFILE=%ThisDir%Usersset APPDATA=%USERPROFILE%\AppData\Roamingset path=%ThisDir%LLVM\bin;%ThisDir%mingw64\bin;%path%REM Code.exe --extensions-dir "extensions"Code.exe !Code\C++\code.code-workspace!start.vbs
set ws=createobject("wscript.shell")ws.run "start.bat",0launch.json
{ "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "internalConsoleOptions": "neverOpen", "MIMode": "gdb", "miDebuggerPath": "gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": false } ], "preLaunchTask": "Compile" } ]}tasks.json
{ "version": "2.0.0", "tasks": [ { "label": "Compile", "command": "clang++", //如果你是用c语言,改成clang "args": [ "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}.exe", "-g", "-Wall", "-static-libgcc", "--target=x86_64-w64-mingw", ], "type": "process", "group": { "kind": "build", "isDefault": true }, "presentation": { "echo": true, "reveal": "always", "focus": false, "panel": "shared" }, } ]}settings.json
{ "files.defaultLanguage": "c", "editor.formatOnType": true, "editor.suggest.snippetsPreventQuickSuggestions": false, "editor.acceptSuggestionOnEnter": "off",
"code-runner.runInTerminal": true, "code-runner.executorMap": { "c": "cd $dir && clang '$fileName' -o '$fileNameWithoutExt.exe' -Wall -g -O2 -static-libgcc --target=x86_64-w64-mingw -std=c11 && &'$dir$fileNameWithoutExt'", "cpp": "cd $dir && clang++ '$fileName' -o '$fileNameWithoutExt.exe' -Wall -g -O2 -static-libgcc --target=x86_64-w64-mingw -std=c++17 && &'$dir$fileNameWithoutExt'" }, "code-runner.saveFileBeforeRun": true, "code-runner.preserveFocus": true, "code-runner.clearPreviousOutput": false, "code-runner.ignoreSelection": true,
"C_Cpp.clang_formatSortIncludes": true, "C_Cpp.errorSquiggles": "Disabled", "C_Cpp.autocomplete": "Disabled", "C_Cpp.suggestSnippets": false,}compile_flags.txt
-Wall--target=x86_64-w64-mingw-std=c++17#写的语言是C,注释掉上面那行