vscode tasks.jaon, launch.json, c_cpp_properties.json 개발환경

markyang92·2022년 7월 18일
1

개발환경

목록 보기
4/7
  1. vscode는 관리하는 디렉토리(workspace)에 .vscode로 아래 3개의 파일을 둘 수 있다.
    1.1. tasks.json: 컴파일러 빌드 셋팅
    1.2. launch.json: 디버거 셋팅
    1.3. c_cpp_properties.json: 컴파일러 path, intellisense setting

  1. 자신의 C/C++ compiler 버전을 보자.
    2.1. 현재 MacOS 를 사용하며, clang을 사용한다.
$ gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.5 (clang-1205.0.22.9)
Target: arm64-apple-darwin21.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

  1. workspace에서 vscode를 실행한다.
    3.1. workspace: cpp_exercise
  • 터미널로 본인의 workspace에 들어가
    $ code .
    로 주로 실행하는 편이다.

tasks.json: build

  • tasks.jsonworkspace에서 build 관리한다.
    • .vscode/tasks.json을 따로 만들거나
    • .c, .cpp 파일 하나 작성하면 옆에 템플릿으로 만들 수 있는 칸이 뜬다.\

  • 누르면, compiler를 선택하는 것이 뜬다.
    어짜피 다 안에서 설정할 수 있기 때문에, 아무거나 누른다.

  • tasks.json 템플릿이 나왔다.
    • 간단한 소스 컴파일, 빌드를 구성할 수 있다.
  • command: 컴파일러 선택
    • clang++ 쓸거라 which clang++로 나오는 경로를 찍었다.
  • args: 컴파일러에 넘겨줄 argument
    • -g: 디버깅 심볼을 넣는 컴파일 옵션

mac

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "clang++ 활성 파일 빌드",
            "command": "/usr/bin/clang++",
            "args": [
                "-std=c++14",
                "-stdlib=libc++",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "디버거에서 생성된 작업입니다."
        }
    ],
    "version": "2.0.0"
}

ubuntu

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ 활성 파일 빌드",
            "command": "/usr/bin/g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "디버거에서 생성된 작업입니다."
        }
    ],
    "version": "2.0.0"
}

  • 파일 실행을 누르면, tasks.json이 먹혀서 돌아간다.


launch.json : gdb 설정


c_cpp_properties.json

profile
pllpokko@alumni.kaist.ac.kr

0개의 댓글