VSCODE로 컴파일을 하다가 터미널에 갑자기 이런식으로 뜨면서 넘어가지를 않았다.
gcc.exe: error (경로): No such file or directory
gcc.exe: fatal error: no input files compilation terminated.
읽어보니까 경로부분에 역슬래시()가 전부 다 빠져있었다. 예를 들면,
C:\Users\aaa\Desktop\aaa\cmania\hell\hellc.exe 라고 되야 할 것이
C:UsersaaaDesktopaaacmaniahellhellc.exe 이런식으로 되어 있던 것이다.
문제를 해결하는데 이틀이나 걸렸다.
git-bash에서 파일 경로 구분자를 /가 아니라 \로 사용하기 때문에 기본 터미널을 powershell로 바꾸면 해결이 된다는 사람이 있었다.
다른 방법은 task.json의 내용을 수정하는 것이다.
원래 코드
//C 컴파일
{
"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
}
}
},
// 바이너리 실행(Windows)
{
"label": "execute",
"command": "cmd",
"group": "test",
"args": [
"/C", "${fileDirname}\\${fileBasenameNoExtension}"
]
}
터미널이 git-bash라면 args에 있는 ${file} 때문에 경로가 windows에서만 작동하는 백슬래시로 나오기 때문에 문제가 생긴다고 한다.
그래서 작은 따옴표로 백슬래시로 된 경로를 감싸면 해결이 된다더라.
바이너리 실행 부분의 command에 cmd를 없애버리고 args 부분도 작은 따옴표로 감싼다. (경로에 한글이 있다면 영어로 바꿔준다.)
바꿔줄 코드
//C 컴파일
{
"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
}
}
},
//바이너리 실행(Windows)
{
"label": "execute",
"command": "",
"group": "test",
"args": ["'${fileDirname}\\${fileBasenameNoExtension}.exe'"]
}
]
}
이것 저것 다해봐도 계속 안 고쳐지길래 Atom으로 바꿀라다가 간신히 방법을 찾았다. 참 다행이다.
복받으세요