줘이리의 인생적기

visual studio code에서 c++ 개발환경 세팅 본문

취미/잡

visual studio code에서 c++ 개발환경 세팅

줘이리 2020. 7. 29. 08:00
728x90

 

https://code.visualstudio.com/download

 

Download Visual Studio Code - Mac, Linux, Windows

Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows. Download Visual Studio Code to experience a redefined code editor, optimized for building and debugging modern web and cloud applications.

code.visualstudio.com

 

https://sourceforge.net/projects/mingw-w64/files/mingw-w64/

 

1. 위 두 가지 환경에 맞게 다운로드한다.

 

 

2. 먼저 mingw를 default값으로 다운로드하고, 아래와 같이 4가지를 체크를 한다.

mingw-developer-tookit, mingw32-base, mingw32-gcc-g++, msys-base

 

아래와 같이 Installation에서 apply chanes를 누른 후 vscode로.

 

 

3. vscode에서 ctrl + shift + x를 누르면 확장 탭이 열리는데 c++을 검색해서 install 해준다

 

4. 다음은 시스템 환경 변수 설정.

윈도우 버튼을 누르고 '시스템 환경 변수 편집'을 검색.

 

 

왼쪽부터 시스템 속성에서 환경변수를 들어가서

시스템 변수의 Path를 찾아 편집을 눌러서

맨 오른쪽 환경변수편집 창을 띄운다.

 

새로만들기를 눌러서 아래와 같이 C:\MinGW\bin을 추가.

 

 

5. 이제 vscode로 돌아가서 터미널 - 기본 빌드 작업 구성을 선택.

템플릿에서 tasks.json 파일 만들기 - Others 선택.

tasks.json 파일을 눌러서 아래와 같이 수정.

더보기

{

    "version""2.0.0",

    "runner""terminal",

    "type""shell",

    "echoCommand"true,

    "presentation" : { "reveal""always" },

    "tasks": [

        {

            "label""save and compile for C++",

            "command""g++",

            "args": [

                "${file}",

                "-g",

                "-o",

                "${fileDirname}/${fileBasenameNoExtension}"

            ],

            "group""build",

            "problemMatcher": {

                "fileLocation": [

                    "relative",

                    "${workspaceRoot}"

                ],

                "pattern": {

                    "regexp""^(.*):(\\d+):(\\d+):\\s+(warning error):\\s+(.*)$",

                    "file"1,

                    "line"2,

                    "column"3,

                    "severity"4,

                    "message"5

                }

            }

        },

        {

            "label""save and compile for C",

            "command""gcc",

            "args": [

                "${file}",

                "-g",

                "-o",

                "${fileDirname}/${fileBasenameNoExtension}"

            ],

            "group""build",

            "problemMatcher": {

                "fileLocation": [

                    "relative",

                    "${workspaceRoot}"

                ],

                "pattern": {

                    "regexp""^(.*):(\\d+):(\\d+):\\s+(warning error):\\s+(.*)$",

                    "file"1,

                    "line"2,

                    "column"3,

                    "severity"4,

                    "message"5

                }

            }

        },

        {

            "label""execute",

            "command""cmd",

            "group""test",

            "args": [

                "/C",

                "${fileDirname}\\${fileBasenameNoExtension}"

            ]

        },

        {

            "type""shell",

            "label""g++.exe build active file",

            "command": "C:\\minGW\\bin\\g++.exe",

            "args": [

                "-g",

                "${file}",

                "-o",

                "${fileDirname}\\${fileBasenameNoExtension}.exe"

            ],

            

            "problemMatcher": [

                "$gcc"

            ],

            "group""build"

        }

    ]

}

위와 같이 파일 수정을 한 후 저장.

 

 

6. 다음으로 Ctrl + shift + P 를 눌러 c/c++: 구성 편집(UI) 입력하여 선택

다음 2가지를 아래와 같이 변경.

 

7. 마지막으로 단축키 설정.

파일 - 기본설정 - 바로가기 키 로 들어가서 

오른쪽 종이모양 바로가기 키 열기를 누르고 다음과 같이 입력한다.

 

8. 이제 파일을 만들고 

ctrl + shift + c 로 컴파일

ctrl + shift + r 로 실행하면 끝