1. tasks.json 이용한 컴파일
작업에 필요한 여러 명령어들을 정의하는 파일이다.
명령 팔레트 이용하거나 직접 '.vscode' 폴더와 'tasks.json' 파일을 추가하는 방법이 있다.
명령 팔레트를 이용한 방법을 이용했다.
1. 'F1'키를 누르고 'tasks'를 입력
2. 'Tasks: Configure ~~' 선택 (없으면 '파일 만들기' -> 'Others' 선택)
3. '.c' 컴파일 후 '.exe' 실행파일 만들기 (build)
tasks.json 파일에서 "tasks": [ ] 의 색칠된 위치에 아래 내용들을 넣어주면 된다.
{
"type": "shell",
"label": "gcc.exe build active file",
"command": "gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
- type : vscode 내 shell에서 작업
- label : 간단한 이름 (설명)
- command : 명령어 (c언어는 'gcc', c++는 'g++')
- args : 명령어 뒤
- problemMatcher : 컴파일에서 에러 확인
- group : 'build', 'test', 'none'으로 그룹 지정
4. '.exe' 실행파일 실행하기 (test)
{
"type": "shell",
"label": "Run",
"command": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "test",
"isDefault": true
}
}
5. build, test 실행 확인하기
tasks.json 파일
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "gcc.exe build active file",
"command": "gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "Run",
"command": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "test",
"isDefault": true
}
}
]
}
2. terminal에서 컴파일
- 컴파일 : gcc -o [실행 파일명] [소스코드명]
- 실행 : ./[실행파일명]

gcc -o study_1 study.c // 'study.c' 파일을 컴파일하고 'study_1' 실행파일 생성
./study_1 // 'study_1' 실행파일 실행
Hello World! // 실행 -> 내용 출력
'etc > study' 카테고리의 다른 글
[Architecture] '레이어드 아키텍처에서 인터페이스 잘 사용하면 그게 헥사고날 아키텍처 아닌가?'에 대한 의문을 해결해보자 (1) | 2024.10.11 |
---|---|
[Spring] 새로운 마음으로 Spring 시작하기 (with 토비의 스프링 + 공식 문서) (0) | 2024.08.05 |
Git (깃), Github (깃헙), Git Bash, Sourcetree (소스트리) (0) | 2020.10.13 |
Git 과 GitHub (0) | 2020.05.17 |