내가 보기 위한 VSCODE C설정

이성준·2023년 2월 20일
2

C 자료구조

목록 보기
2/12

Visual Studio를 사용하기에는 나는 파이썬을 주로 사용해서 좀 무겁다는 생각을 해서 VS Code를 사용해야겠다는 생각을 했다.

Transformer는 작성중에 있다.. 이런저런 실험을 하다 보니 시간이 잘 안나서 뒤로 좀 미뤘다 하지만 계속 복습을 하니 좋을수도..?

VS Code에서 C와 관련된 프로그램들을 다운을 받고 나서 예전에 혼자 C언어를 공부할때 ctrl+F5로 디버깅 했던게 생각이 나서 눌러봤는데 오류가 떴다.
여기서 일단 알고 있어야 하는게 VS Code는 코드를 편집하는 코드 편집기 라는 사실이다.
따라서 실질적인 동작은 내 PC의 Terminal에서 수행하게 되는데, 그래서 Build 작업을 꼭 거쳐줘야한다. 그래서 찾아보니깐 MinGW를 깔아야 했다. 깔고나서 이런저런 설정을 맞추는데 자꾸 오류가 나서, 내가 시도해보니깐 되는 설정을 공유하고 앞으로 꾸준히 보려고 Velog를 쓴다.
아래는 launch.json 파일이다

{
    // IntelliSense를 사용하여 가능한 특성에 대해 알아보세요.
    // 기존 특성에 대한 설명을 보려면 가리킵니다.
    // 자세한 내용을 보려면 https://go.microsoft.com/fwlink/?linkid=830387을(를) 방문하세요.
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) 시작",
            "type": "cppvsdbg",
            "request": "launch",
            //"program": "프로그램 이름 입력(예: ${workspaceFolder}/a.exe)",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "console": "externalTerminal"
        }
    ]
}

아래는 tasks.json 파일이다

{
    "version": "2.0.0",
    "runner": "terminal",
    "type": "shell",
    "echoCommand": true,
    "presentation": {
        "reveal": "always"
    },
    "tasks": [
        {
            "label": "save and compile for C",
            "command": "gcc",
            "args": [
                "${file}",
                "-g",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "group": "build",
            "problemMatcher": {
                "fileLocation": [
                    "relative",
                    "${workspaceFolder}"
                ],
                "pattern": {
                    "regexp": "^([^\\\\s].*)\\\\((\\\\d+,\\\\d+)\\\\):\\\\s*(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        },
        {
            "label": "execute",
            "command": "cmd",
            "group": "test",
            "args": [
                "/C",
                "${fileDirname}\\${fileBasenameNoExtension}"
            ]
        },
        {
            "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": "cppbuild",
            "label": "C/C++: gcc.exe 활성 파일 빌드",
            "command": "C:/MinGW/bin/gcc.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "C:/MinGW/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "디버거에서 생성된 작업입니다."
        }
    ]
}

전체적인 참고는 다음 블로그 에서 했다!

profile
Time-Series

0개의 댓글