Windows 환경
1. gcc(컴파일러) 설치
MinGW 다운로드
sourceforge.net/projects/mingw/

MinGW Setup




mingw-developer-toolkit, mingw32-base, mingw32-gcc-g++. msys-base 체크
Installation -> Apply Changes

2. 환경 변수 설정
환경 변수





C:\MinGW\bin 경로 추가


실행(Windows Key + R) -> CMD or 명령 프롬프트 실행
g++ --version gcc --version
3. VS Code 설정
VS Code


VS Code] Ctrl + Shfit + X -> C/C++



② 파일명 작성
③ 코드 작성
#include <stdio.h>
int main()
{
printf("Test");
return 0;
}



C/C++: gcc.exe 활성 파일 빌드 선택 후 생성되는 tasks.json 수정 후 저장(Ctrl + S)
k.kakaocdn.net/dn/brDC5p/btqFn0fPsBW/B75rJiBqICBUkxkxMahI21/tfile.txt
{
"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
}
}
},
// // 바이너리 실행(Windows)
{
"label": "execute",
"command": "cmd",
"group": "test",
"args": [
"/C",
"${fileDirname}\\${fileBasenameNoExtension}"
]
}
]
}



Keybindings.json 수정 후 저장(Ctrl + S)
k.kakaocdn.net/dn/bHhiX4/btqFnwGB6cs/JjH0MCuwrGT1PavzRu6921/tfile.txt
// Place your key bindings in this file to override the defaults
// 아래 키 바인딩을 파일에 넣어서 기본값을 덮어 씁니다.
[
// 컴파일
{
"key": "ctrl+alt+c",
"command": "workbench.action.tasks.build"
},
// 실행
{
"key": "ctrl+alt+r",
"command": "workbench.action.tasks.test"
}
]

Keybindings.json에서 작성한 단축키 Keyboard Shortcuts에서 확인

단축키 : Ctrl + Alt + C ※(Keybindings.json, Keyboard Shortcuts에서 설정한 단축키)
① 컴파일 C/C++ 선택 ② 터미널 결과 ③ 컴파일 결과

단축키 : Ctrl + Alt + R ※(Keybindings.json, Keyboard Shortcuts에서 설정한 단축키)
Test 출력 확인
참고 1. VS Code(Visual Studio Code) 참고 2. 참고 3. |
'Coding > C' 카테고리의 다른 글
분기문(if, if ~ else, switch) (0) | 2021.06.12 |
---|---|
반복문(while, do ~ while, for) (0) | 2021.06.06 |
연산자 (0) | 2021.06.05 |
C언어 변수와 입·출력(scanf, printf) 그리고 주석 (0) | 2021.05.29 |
C언어 기본 구조 (0) | 2021.05.09 |