C언어
C언어 - VSCode C/C++ 개발환경 세팅 : C / C++ Extension 설치 및 json 파일 세팅(Windows)
깅햄찌
2022. 9. 4. 20:35
반응형
안녕하세요! 저번 포스팅에 이어서 VSCode C/C++ 개발환경 세팅을 진행해보겠습니다. 오늘은 아래 3가지 세팅 + C Code 실행까지 완료해보겠습니다.
1. VSCode C / C++ Extension 설치
2. IntelliSense 설정을 위한 c_cpp_properties.json 수정
3. Compile + Execute를 위한 tasks.json 수정
아직 Compiler를 설치 못한 분들은 저번 포스팅을 참고해주세요~
2022.09.03 - [C언어] - C언어 - VSCode C/C++ 개발환경 세팅 : MSYS2(mingw64 Compiler) 설치 (Windows)
C언어 - VSCode C/C++ 개발환경 세팅 : MSYS2(mingw64 Compiler) 설치 (Windows)
안녕하세요 오늘은 VSCode에서 C/C++ 언어로 코딩하기 위해 필요한 개발 환경 세팅 메뉴얼을 작성해보려고 합니다!! 이번 포스팅에서는 2가지를 해보겠습니다. 1. Compiler이 되는지 알아보기 위한 Test
leggo-fire.tistory.com
1. VSCode에 C / C++ Extension을 설치
VSCode를 열고 좌측 Tab에 Extensions를 클릭하고 "C / C++"를 검색합니다.
(Ctrl + Shift + X를 눌러도 Extensions에 들어갈 수 있습니다~ )
Install 버튼을 눌러 C / C++ Extensions를 설치해줍니다.
C / C++ Extensions을 설치하면 아래와 같은 장점이 있습니다.
1. 코드 하이라이트 (Colorization)
2. 코드 자동완성 (IntelliSense)
3. 오류 검사 (Error Check)
다음과 같은 이유들 때문에 IDE를 쓰는 거겠죠?
![](https://t1.daumcdn.net/keditor/emoticon/friends1/large/006.gif)
2. IntelliSense 설정을 위한 c_cpp_properties.json 수정
코드 자동완성 등 코딩을 보다 편리하게 하는 기능을 이용하기 위한 IntelliSense를 설정해야 합니다.
Ctrl + Shift + p를 입력하고 아래 그림처럼 C/C++: Edit Configurations를 클릭합니다.
Windows니까 구성 이름에 Win32를 선택하고 Compiler의 path를 컴파일러 경로에 적어줍니다.
(이전 포스팅에서 참고하시면 Compiler path를 쉽게 복사할 수 있어요~ )
Windows 64bit 운영체제에 gcc Compiler를 이용할 것이므로
IntelliSense 모드를 windows-gcc-x64로 선택합니다.
설정을 마치면 작업폴더에 .vscode라는 파일이 생기고 그 안에 c_cpp_properties.json이 생겼으면
IntelliSense 설정이 끝났습니다.
3. Compile + Execute를 위한 tasks.json 수정
VSCode에서 C code Compile과 Execute를 위해 tasks.json을 수정할 것입니다.
Ctrl + Shift + p를 입력하고 아래 그림처럼 Tasks: Configure Task를 클릭합니다.
Create tasks,json from template를 클릭합니다.
Others를 클릭합니다.
좌측 작업폴더에 tasks.json파일이 생성됩니다.
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": "cppbuild",
"label": "C/C++: g++.exe",
"command": "C:/msys64/mingw64/bin/gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:/msys64/mingw64/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Taks created from Debbuger"
}
]
}
자 이제 C code를 build&execute 하기 위한 모든 Setting이 끝났습니다.
먼저 아래 Test code를 build 해보겠습니다.
#include <stdio.h>
int main(void){
printf("Hello_World");
return 0;
}
gcc 컴파일러를 써보신 분들은 익숙할 텐데요.
terminal에 gcc -o (실행파일 이름) (build 할 파일 이름)을 입력하면
아래 그림과 같이 좌측 작업 폴더에 실행 파일이 생깁니다.
혹은 Ctrl + Alt + C로 build를 해줍니다.
터미널에서 .\(실행 파일 이름)을 입력하면 Code가 실행되고 아래 그림처럼
Hello World가 출력되는 것을 확인할 수 있습니다.
혹은 Ctrl + Alt + N으로 build + execute를 동시에 해줍니다.
오늘은 아래 3가지 세팅 + C Code 실행까지 완료해봤는데요.
1. VSCode C / C++ Extension 설치
2. IntelliSense 설정을 위한 c_cpp_properties.json 수정
3. Compile + Execute를 위한 tasks.json 수정
VSCode 에서 C/C++ 실행시키기 쉽지 않네요 ㅠ
![](https://t1.daumcdn.net/keditor/emoticon/friends1/large/015.gif)