Table of Contents
-
下記リンクをクリック&ダウンロードページへ
MingW-W64-builds -
SourceForgeのサイトからダウンロード
-
exe ファイルをクリックして実行、インストールを開始する
-
Settings
のところ`でx86_64
,win32
を選ぶ。ほか、インストール先(D:\Runtime\mingw-w64
とか)を選んだりしてインストール実行。
-
メニューから
View
>Command Palette
orCtrl + Shift + P
押して「C/C++」を入力し、C/C++ : Edit Configurations (UI)
を選択 -
コンパイラ パス
にg++.exeへのパスを設定する。
※例:D:\Runtime\mingw-w64\mingw64\bin\g++.exe
※結果、.vscode/c_cpp_properties.json
が出力される。
{
// tasks.json 形式の詳細についての資料は、
// https://go.microsoft.com/fwlink/?LinkId=733558 をご覧ください
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "D:/Runtime/mingw-w64/mingw64/bin/g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:/Runtime/mingw-w64/mingw64/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
-
ソースを書く
#include <string> int main() { std::string hello = "Hello C++!"; puts( hello.c_str() ); return 0 ; }
-
ビルドする
エディタでソースを開いた状態でShift + Ctrl + B
を入力。
exeファイルが出来ていればOK。 -
必要なdllをコピー同フォルダにコピーする。
上記サンプルコードで必要なのは下記DLL。-
libwinpthread-1.dll
-
libgcc_s_seh-1.dll
-
libstdc++-6.dll
-
launch.json
{
// IntelliSense を使用して利用可能な属性を学べます。
// 既存の属性の説明をホバーして表示します。
// 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe - build & debug",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:\\Runtime\\mingw-w64\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "gdb の再フォーマットを有効にする",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}
+ テストしてみる。適当なところにブレークポイント置いて、F5押して止まればOK!