방법1.

@ 참고 : https://webnautes.tistory.com/1158

▶ #1, #2, #5는 참고2 활용

#1. C/C++ 컴파일러(MinGW) 설치
#2. 'Code Runner' 확장 기능 설치
#3. 메뉴 > 터미널 > 기본 빌드 작업 구성 -> 탐색기에 tasks.json파일이 추가됨
#4. tasks.json의 내용을 다음으로 교체

{
    "version": "2.0.0",
    "runner": "terminal",
    "type": "shell",
    "echoCommand": true,
    "presentation" : { "reveal": "always" },
    "tasks": [
          //C++ 컴파일
          {
            "label": "save and compile for C++",
            "command": "g++",
            "args": [
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "group": "build",

            //컴파일시 에러를 편집기에 반영
            //참고:   https://code.visualstudio.com/docs/editor/tasks#_defining-a-problem-matcher

            "problemMatcher": {
                "fileLocation": [
                    "relative",
                    "${workspaceRoot}"
                ],
                "pattern": {
                    // The regular expression. 
                   //Example to match: helloWorld.c:5:3: warning: implicit declaration of function 'prinft'
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        },
        //C 컴파일
        {
            "label": "save and compile for C",
            "command": "gcc",
            "args": [
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "group": "build",

            //컴파일시 에러를 편집기에 반영
            //참고:   https://code.visualstudio.com/docs/editor/tasks#_defining-a-problem-matcher

            "problemMatcher": {
                "fileLocation": [
                    "relative",
                    "${workspaceRoot}"
                ],
                "pattern": {
                    // The regular expression. 
                   //Example to match: helloWorld.c:5:3: warning: implicit declaration of function 'prinft'
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        },
        // 바이너리 실행(Ubuntu)
        // {
        //     "label": "execute",
        //     "command": "cd ${fileDirname} && ./${fileBasenameNoExtension}",
        //     "group": "test"
        // }
        // 바이너리 실행(Windows)
        {
            "label": "execute",
            "command": "cmd",
            "group": "test",
            "args": [
                "/C", "${fileDirname}\\${fileBasenameNoExtension}"
            ]
    
        }
    ]
}

** 이때 단축키 설정해서 사용하면 window has crashed 에러 메세지 뜨므로 단축키 없이 실행!!

#5. 파일 실행(단축키: Ctrl + Alt + N)


방법2. 실행했을 때 output의 encoding이 깨짐

@ 참고 : https://taking.kr/blog/archives/4825.html

#1. MinGW 다운로드

1. https://sourceforge.net/projects/mingw/files/latest/download 다운로드를 통해 설치를 진행한다.
2. 설치 후, MinGW Installation Manager에 다음 패키지를 선택 후, Apply Changes를 눌러 설치한다.

- mingw-developer-toolkit

- mingw32-base

- mingw32-gcc-g++

-msys-base

3. 컴퓨터 -> 속성 -> 고급 시스템 설정 -> 시스템 속성[고급 탭] -> 환경 변수 -> Path 변수에
C:\MinGW\bin을 추가한다.
4. 정상적으로 gcc / g++ 컴파일러가 설치되었는지 확인하기 위해 명령 프롬프트(cmd)를 켜 확인해본다.

- gcc --version

- g++ --version

#2. VS Code 컴파일 환경설정

1. 확장 마켓플레이스에서 'Code Runner'를 설치한다.
- 지원 언어 : C, C++, Java, Python, Visual Basic .Net, Kotlin 등
2. 설정(ctrl+,) -> {} settings.json 안에 다음 설정 추가

   // Code Runner "CPP" 설정

    "code-runner.executorMap": {

    "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"

    },

    // Window 10 에서는 Default Shell 이 Powershell이기 때문에 cmd로 변경해야 정상적으로 실행 됨.

    "terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\cmd.exe"

3. 파일 생성 후 실행(단축키: Ctrl+Alt+N)

- helloworld.c

#include <stdio.h>

int main() {
    printf("안녕\n");
    return 0;
}

- helloworld.cpp

#include <iostream>
using namespace std;

int main() {
    cout << "안녕" << endl;
    return 0;
}

'프로그램 설치' 카테고리의 다른 글

이클립스 CDT로 C/C++ 개발 시작하기  (0) 2019.09.05
블로그 이미지

uchacha

개발자 일지

,