[C/C++] Unable to start debugging. Unexpected GDB output from command -environment-cd

merong·2024년 3월 30일
0

⚠ERROR! 모음zip

목록 보기
5/5

VScode에서의 C 실행

아마도 당신은 VScode에서 c code를 실행하려다가 위와 같은 에러를 마주하게 되었을 것이다.
이 에러가 발생했던 환경과 그 해결하는 방법을 기록해보도록 하겠다!

발생 배경

  1. 이미 mingw64가 깔려있는 상황 (path : "C:\msys64\mingw64\bin")
  2. 시스템 환경 변수도 추가된 상태
  3. vscode c/c++ extension도 설치된 상태
  4. c_cpp_properties.json, launch.json, tasks.json이 모두 올바르게 작성된 상태 (참조 블로그)

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:/msys64/mingw64/include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\msys64\\mingw64\\bin\\gcc.exe",
            "cStandard": "c17",
            "cppStandard": "gnu++17",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}

launch.json

{
    "version": "0.2.0",
    "configurations": [
    
        {
            "name":"(gdb)시작",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "gdb에 자동 서식 지정 사용",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

tasks.json

{
    "version": "2.0.0",
    "runner": "terminal",
    "type": "shell",
    "echoCommand": true,
    "presentation": {
        "reveal": "always"
    },
    "tasks": [
        // c++ compile
        {
            "label": "save and compile for C++",
            "command": "g++",
            "args": [
            "${file}",
            "-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
                }
            }
        },
        // c compile
        {
            "label": "save and compile for C",
            "command": "gcc",
            "args": [
            "${file}",
            "-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++: gcc.exe build active file",
            "command": "C:\\msys64\\mingw64\\bin\\gcc.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
}

5. 그리고 마지막으로.. c 파일 경로에 한글이 포함된 상태

원인과 해결방법

에러는 역시 '설마..? ' 했던 곳에서 일어나는 법이다.

c 파일 경로에 한글이 포함되어 있었던 게 원인이었다.
나의 경우 "D:/내이름/project" 이런식의 경로에 c 파일이 있었는데, "D:/project" 로 워크스페이스를 새로 파서 거기서 실행해주니 잘 작동하였다.

일단.. 꼭 경로에서 한글을 제외하시고 실행해보시길!!! 🍀💚

profile
매일매일이 새로운 시작점

0개의 댓글