-
sudo apt-get install build-essential
-
Install C/C++ extensions
-
ctrl + shift + P
$\rarr$ C/C++:구성 편집(UI)- 컴파일러 선택 C : gcc, C++ : gcc++
- IntelliSence 모드 : linux-gcc-x64
- 설정을 저장하고 나면
.vscode
폴더에c_cpp_properties.json
파일이 만들어진다.
-
터미널 → 작업 구성 → 템플릿에서 tasks.json 파일 만들기 → Others 선택.
-
.vscode
폴더에서tasks.json
에 아래 내용 복사/붙여넣기.{ "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 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 } } }, // 바이너리 실행(Ubuntu) { "label": "execute", "command": "${fileDirname}/${fileBasenameNoExtension}", "group": "test" } // 바이너리 실행(Windows) // { // "label": "execute", // "command": "cmd", // "group": "test", // "args": [ // "/C", "${fileDirname}\\${fileBasenameNoExtension}" // ] // } ] }
-
g++ -o ./실행파일경로 test.cpp
로 빌드 -
./test 로 실행.