Creating a Portable C++ VS Edition (Based on VSCode)

正文

不想动手可以直接下载的懒人版,密码QRSJ

  • VSCode
  • LLVM
  • mingw64

下载VSCode

注意选择下载压缩包格式。


下载LLVM

不需要选sig文件

注意选择”Pre-Built Binaries”,系统位数要对应你上面选的!


下载MinGW-W64

如果你系统版本是x64,下载x86_64-posix-seh。

如果你系统版本是x32,下载x86_64-win32-seh。


1.解压VSCode到某个地方,再把MinGW解压到VSCode的目录里

我做这几部只是为了得到LLVM目录,卸载掉它只是因为不想让程序列表里太多非强迫症可以忽略2-4步,直接选择安装目录到第一步文件夹里

2.安装LLVM,先随便安装到一个位置

3.把LLVM目录整个拷到第1步里的目录里

4.卸载掉你系统里的LLVM

5.将附件中!start.vbs和start.bat复制到第一步的文件夹中

6.注释掉start.bat最后一行就是在最后一行前面加::

7.**!!这一步做完不要关!!**在cmd(或者power shell)中输入.\start.bat运行脚本,然后输入clang和gcc.如果出现xxx不是内部或外部命令,就说明你start.bat配置有问题

8.在你第1步的文件夹中新建以下名字的文件夹

1
2
3
4
5
6
7
Users
Users\AppData
Users\AppData\Local
Users\AppData\Roaming
Users\AppData\Desktop

extensions

9.安装扩展

1
2
3
4
5
6
Chinese(简中语言包)
C/C++
vscode-clangd
Code Runner
Bracket Pair Colorizer 2
One Dark Pro(主题包,可选)

10.在第7步中的cmd(或power shell)中输入.\code.exe进入VSCode

11.在文件浏览器中新建一个目录(我就直接在第1步的目录中新建了一个!Code),然后在VSCode中打开它,然后选择将工作区另存为

需要注意的是这里你把每个语言的工作目录放到单独的文件夹中,比如c放到c中,c++放到c++中

12.在!Code中又新建一个名叫C++的文件夹**(具体参照自身情况)**

13.在C++目录中新建一个.vscode的文件夹,然后在里面把附件中的launch.json,tasks.json,settings.json,compile_flags.txt复制进去

14.取消第6步中的注释,关掉这个VSCode.运行!start.vbs

15.新建一个文件,输入点什么测试代码

1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;
int main (){
string a="";
cout << "Input:" << endl;
cin >> a;
cout << a;
return 0;
}

16.点击右上箭头,看看控制台是不是输出了Input:.然后输入随便什么东西,看看它会不会原封不动的显示出来

17.没了

附件


start.bat

1
2
3
4
5
6
set ThisDir=%~dp0
set USERPROFILE=%ThisDir%Users
set APPDATA=%USERPROFILE%\AppData\Roaming
set path=%ThisDir%LLVM\bin;%ThisDir%mingw64\bin;%path%
REM Code.exe --extensions-dir "extensions"
Code.exe !Code\C++\code.code-workspace

!start.vbs

1
2
set ws=createobject("wscript.shell")
ws.run "start.bat",0

launch.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{
"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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{
"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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"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_format_sortIncludes": true,
"C_Cpp.errorSquiggles": "Disabled",
"C_Cpp.autocomplete": "Disabled",
"C_Cpp.suggestSnippets": false,
}

compile_flags.txt

1
2
3
4
-Wall
--target=x86_64-w64-mingw
-std=c++17
#写的语言是C,注释掉上面那行

Main Content

Lazy version ready for direct download, password: QRSJ

  • VSCode
  • LLVM
  • mingw64

Download VSCode

Note: Choose to download the compressed package format.


Download LLVM

Do not select the sig file.

Note: Choose “Pre-Built Binaries”, and ensure the system architecture matches your selection above.


Download MinGW-W64

For x64 systems, download x86_64-posix-seh.
For x32 systems, download x86_64-win32-seh.


  1. Extract VSCode to a specific location, then extract MinGW into the VSCode directory.

I performed these steps only to obtain the LLVM directory. Uninstalling it later is just to avoid having too many entries in the programs list. Non-OCD viewers can ignore steps 2-4 and directly choose the installation directory from step 1’s folder.

  1. Install LLVM, initially install it anywhere.
  2. Copy the entire LLVM directory into the directory from step 1.
  3. Uninstall LLVM from your system.
  4. Copy the attached files !start.vbs and start.bat into the folder from step 1.
  5. Comment out the last line of start.bat by adding :: before the last line.
  6. !!After completing this step, do not close the window!! In cmd (or PowerShell), run the script by typing .\start.bat, then type clang and gcc. If you see ‘xxx’ is not recognized as an internal or external command, your start.bat configuration has an issue.
  7. Create the following folders with these exact names in your step 1 folder.
1
2
3
4
5
6
7
Users
Users\AppData
Users\AppData\Local
Users\AppData\Roaming
Users\AppData\Desktop

extensions
  1. Install extensions.
1
2
3
4
5
6
Chinese (Simplified Language Pack)
C/C++
vscode-clangd
Code Runner
Bracket Pair Colorizer 2
One Dark Pro (theme pack, optional)
  1. In the cmd (or PowerShell) window from step 7, enter .\code.exe to launch VSCode.
  2. In the file explorer, create a new directory (I simply created one named !Code within the step 1 directory). Then open it in VSCode and choose to save the workspace as…

Note: Organize each language’s working directories into separate folders, for example, place C in a ‘c’ folder and C++ in a ‘c++’ folder.
12. Within !Code, create another folder named C++ (adjust based on your specific situation).
13. Inside the C++ directory, create a .vscode folder. Then copy the attached files launch.json, tasks.json, settings.json, and compile_flags.txt into it.
14. Remove the comment from step 6. Close this VSCode instance. Run !start.vbs.
15. Create a new file and type in some test code.

1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;
int main (){
string a="";
cout << "Input:" << endl;
cin >> a;
cout << a;
return 0;
}
  1. Click the arrow in the top-right corner and see if the console outputs “Input:”. Then type something random and see if it displays exactly what you entered.
  2. That’s it.

Attachments


start.bat

1
2
3
4
5
6
set ThisDir=%~dp0
set USERPROFILE=%ThisDir%Users
set APPDATA=%USERPROFILE%\AppData\Roaming
set path=%ThisDir%LLVM\bin;%ThisDir%mingw64\bin;%path%
REM Code.exe --extensions-dir "extensions"
Code.exe !Code\C++\code.code-workspace

!start.vbs

1
2
set ws=createobject("wscript.shell")
ws.run "start.bat",0

launch.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{
"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

1
2
3
4
5
6
{
"version": "2.0.0",
"tasks": [
{
"label": "Compile",
"command": "clang++", // If you are using C, change to clang.
        <span class="hljs-attr">"args"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>
            <span class="hljs-string">"${file}"</span><span class="hljs-punctuation">,</span>
            <span class="hljs-string">"-o"</span><span class="hljs-punctuation">,</span>
            <span class="hljs-string">"${fileDirname}/${fileBasenameNoExtension}.exe"</span><span class="hljs-punctuation">,</span>
            <span class="hljs-string">"-g"</span><span class="hljs-punctuation">,</span>
            <span class="hljs-string">"-Wall"</span><span class="hljs-punctuation">,</span>
            <span class="hljs-string">"-static-libgcc"</span><span class="hljs-punctuation">,</span>
            <span class="hljs-string">"--target=x86_64-w64-mingw"</span><span class="hljs-punctuation">,</span>
        <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>
        <span class="hljs-attr">"type"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"process"</span><span class="hljs-punctuation">,</span>
        <span class="hljs-attr">"group"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span>
            <span class="hljs-attr">"kind"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"build"</span><span class="hljs-punctuation">,</span>
            <span class="hljs-attr">"isDefault"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span>
        <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span>
        <span class="hljs-attr">"presentation"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span>
            <span class="hljs-attr">"echo"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>
            <span class="hljs-attr">"reveal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"always"</span><span class="hljs-punctuation">,</span>
            <span class="hljs-attr">"focus"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>
            <span class="hljs-attr">"panel"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"shared"</span>
        <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span>
    <span class="hljs-punctuation">&#125;</span>
<span class="hljs-punctuation">]</span>

}

settings.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"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_format_sortIncludes": true,
"C_Cpp.errorSquiggles": "Disabled",
"C_Cpp.autocomplete": "Disabled",
"C_Cpp.suggestSnippets": false,
}

compile_flags.txt

1
2
3
4
-Wall
--target=x86_64-w64-mingw
-std=c++17
# If writing in C, comment out the line above.

Creating a Portable C++ VS Edition (Based on VSCode)
https://tokisaki.top/blog/vscode-portable/
作者
Tokisaki Galaxy
发布于
2019年8月27日
许可协议