이 글을 시작하기에 앞서, 세 플랫폼 다 Visual Studio Code로 IDE를 통일해서 씀을 알려드립니다.
.vscode
라는 폴더 안에, 컴파일 작업용 tasks.json
과, 디버그 작업용 launch.json
파일에서 아래 코드로 복붙해 줍시다. 저는 이 코드를 ChatGPT랑 입씨름하며 만들었습니다.{
"version": "2.0.0",
"tasks": [
{
"label": "build C program",
"type": "shell",
"command": "gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/a.out"
],
"group": "build",
"problemMatcher": [
"$gcc"
],
"windows": {
"command": "gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\a.exe"
]
},
"linux": {
"command": "gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/a.out"
]
},
"osx": {
"command": "gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/a.out"
]
}
},
{
"type": "cppbuild",
"label": "C/C++: clang 활성 파일 빌드",
"command": "/usr/bin/clang",
"args": [
"-fcolor-diagnostics",
"-fansi-escape-codes",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "디버거에서 생성된 작업입니다."
}
]
}
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug C (Windows)",
"type": "cppvsdbg",
"request": "launch",
"program": "${fileDirname}\\a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"console": "integratedTerminal",
"preLaunchTask": "build C program"
},
{
"name": "Debug C (Linux)",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"externalConsole": false,
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build C program"
},
{
"name": "Debug C (macOS, CodeLLDB)",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/a.out",
"args": [],
"cwd": "${fileDirname}",
"preLaunchTask": "build C program",
"stopAtEntry": false,
"console": "integratedTerminal"
}
]
}