티스토리 뷰

기본 참고

https://github.com/Microsoft/vscode-cpptools/blob/master/launch.md


컴파일러는 visual studio code에서 기본 제공하지 않는다. mingw를 다운 받아서 하자. <<- 당연히 plugin에서 지원 할 줄 알았는데 -_-;

제일 먼저 할 건.. mingw 설치하고, 환경 변수로 C:\MinGW를 MINGW_HOME으로 잡고 나서, c프로젝트의 설정을 아래 처럼 해주자


일단 의식의 흐름에 따라 정리하면..

1. 가장 중요한 단축키는 컨트롤+쉬프트+P. 그냥 뭔가 컨피그 바꾸고 싶으면 다 여기서 통한다

2. 컨트롤+쉬프트+B 통해서 빌드 할 수 있으며, 이 때 수행할 태스크는 tasks.json에 들어간다. 이 파일은 현재 작업 폴더에 종속적이다. 아래와 같이 입력했다. (디버깅용과 아닌놈은 -g 옵션에 차이가 있다)

{
"version": "2.0.0",
"runner": "terminal",
"type": "shell",
"echoCommand": true,
"presentation" : { "reveal": "always" },
"tasks": [
//C++ 컴파일
{
"label": "save and compile for C++",
"command": "g++",
"args": [
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"group": "build",

//컴파일시 에러를 편집기에 반영
//참고: https://code.visualstudio.com/docs/editor/tasks#_defining-a-problem-matcher

"problemMatcher": {
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
// The regular expression.
//Example to match: helloWorld.c:5:3: warning: implicit declaration of function 'prinft'
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
},

//C++ 디버깅
{
"label": "save and debugging for C++",
"command": "g++",
"args": [
"${file}",
"-g -o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"group": "build",

//컴파일시 에러를 편집기에 반영
//참고: https://code.visualstudio.com/docs/editor/tasks#_defining-a-problem-matcher

"problemMatcher": {
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
// The regular expression.
//Example to match: helloWorld.c:5:3: warning: implicit declaration of function 'prinft'
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
},

//C 컴파일
{
"label": "save and compile for C",
"command": "gcc",
"args": [
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"group": "build",

//컴파일시 에러를 편집기에 반영
//참고: https://code.visualstudio.com/docs/editor/tasks#_defining-a-problem-matcher

"problemMatcher": {
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
// The regular expression.
//Example to match: helloWorld.c:5:3: warning: implicit declaration of function 'prinft'
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
},
//C 컴파일
{
"label": "save and compile for C",
"command": "gcc",
"args": [
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"group": "build",

//컴파일시 에러를 편집기에 반영
//참고: https://code.visualstudio.com/docs/editor/tasks#_defining-a-problem-matcher

"problemMatcher": {
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
// The regular expression.
//Example to match: helloWorld.c:5:3: warning: implicit declaration of function 'prinft'
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
},

//C 디버깅
{
"label": "save and debugging for C",
"command": "gcc",
"args": [
"${file}",
"-g -o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"group": "build",

//컴파일시 에러를 편집기에 반영
//참고: https://code.visualstudio.com/docs/editor/tasks#_defining-a-problem-matcher

"problemMatcher": {
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
// The regular expression.
//Example to match: helloWorld.c:5:3: warning: implicit declaration of function 'prinft'
"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}"
]
}
]
}




3. 컨트롤+쉬프트+P 누르고 c/cpp 검색해서 C/Cpp: Edit Configurations 선택하면 c_cpp_properties.json이라는 놈이 생김. 나는 윈도우를 쓰니까, win32 부분에 아래와 같이 입력함

{
"name": "Win32",
"includePath": [
"${workspaceRoot}",
"${MINGW_HOME}/include",
"${MINGW_HOME}/lib/gcc/mingw32/6.3.0/include-fixed",
"${MINGW_HOME}/lib/gcc/mingw32/6.3.0/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"__GNUC__=6",
"__cdecl=__attribute__((__cdecl__))"
],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"${workspaceRoot}",
"${MINGW_HOME}/include",
"${MINGW_HOME}/lib/gcc/mingw32/6.3.0/include-fixed",
"${MINGW_HOME}/lib/gcc/mingw32/6.3.0/include"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}


4. 디버깅 하려면... 왼쪽 메뉴 중 디버깅 누르고.. 바뀐 화면에서 콤보박스 눌러서 (구성추가)현재 작업 폴더 이름 을 누르고 C++(GDB/LLDB) 를 선택한다.

{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/helloworld/helloworld.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "${MINGW_HOME}/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}

내용은 이렇게 했다. 근데 내가 바보 처럼 mingw 설치할때 gdb를 안깔았더라 -_-; 지금 다시 깔려고 하는데 자꾸 서버 접속 실패 뜬다. 성공해보고 다시 글 써야지. (라고 적어놓고 안쓸확률 99%)



이것 저것 다 해보고 느낀 점은.. 걍 visual studio 2018 같은걸 쓰자 -_-;


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함