Skip to content

Instantly share code, notes, and snippets.

@michaelHL
Last active August 2, 2017 09:45
Show Gist options
  • Save michaelHL/27f2b339478bb9be29120f501c744d73 to your computer and use it in GitHub Desktop.
Save michaelHL/27f2b339478bb9be29120f501c744d73 to your computer and use it in GitHub Desktop.
利用VSCode搭建简易C&C++编译环境

利用VSCode搭建简易C&C++编译环境

1. MinGW GCC工具链

  • (可参考之前的gist: eclipse配置C/C++编译环境)
  • 老版本MinGW仅有32位的Tool Chain, 若需要编译64位程序, 转至MinGW-w64项目(推荐)
  • MinGW GCC 5.4.0 x86为例, 依次在Files界面选择Toolchains targetting Win32, Personal Builds, mingw-builds, 5.4.0, threads-posix, dwarf, i686-5.4.0-release-posix-dwarf-...进行下载. 类似可下载64位以及其他版本的工具链(seh, dwarf, sjlj等)
    直链: i686-5.4.0-release-posix-dwarf-rt_v5-rev0.7z
  • 解压:

    目录结构如下:

  • 添加环境变量:

2. VSCode配置

  • CtrlShiftX打开插件侧边栏, 于搜索框中键入code runner, 安装即可(注意作者是Jun Han).

  • File - Preferences - Settings, 或按下组合键 Ctrl,, 于右侧自定义设置中添加设置:

    {
    "code-runner.executorMap": {
            "c": "cd /d $dir && gcc -std=c99 -Wall $fileName -o $fileNameWithoutExt.exe && $dir$fileNameWithoutExt.exe",
            "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
            "objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        }
    }

    当然参数可以进一步定制. 除此之外, 还可以有如下自定义设置以获更佳体验 (注意json语法)

    {
        "code-runner.saveFileBeforeRun": true,
        "code-runner.runInTerminal": false,
        "code-runner.preserveFocus": true,
        "code-runner.showExecutionMessage": false,
        "code-runner.clearPreviousOutput": true,
    }

    配置完了应该是这样:

  • 开耍.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment