카테고리

asm (27) bootloader_x86_grub (1) C (92) compile (11) config (76) CPP (13) CSS (1) debugging (7) gimp (1) Go (1) html (1) Java (1) JavaScript (1) kernel (19) LibreOffice (3) Linux system progamming (21) MFC (1) opencv (4) OpenGL (1) PHP (1) Python (4) qemu (29) shell (3) socket (7) troubleshooting (2) ubuntu18.04 (2) windows (1)

2018/12/24

우분투 비쥬얼 스튜디오 설치 및 사용방법

1. 설치
1.1 윈도우
1.1.1 다운로드: https://code.visualstudio.com/download
1.1.2 환경설정
기타: "Code(으로 열기" 작업를 Windows 탐색기 파일의 상항에 맞는 메뉴에 추가
기타: "Code(으로 열기" 작업를 Windows 탐색기 디렉토리의 상항에 맞는 메뉴에 추가
기타: Code를 지원되는 파일 형식에 대한 편집기로 등록한다.
기타: PATH에 추가(다시 시작한 후 사용 가능)

1.2 우분투
1.2.1 다운로드
저장소 GPG 키 등록
sudo sh -c 'curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/microsoft.gpg'

저장소 추가
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'

설치
sudo apt-get update
sudo apt-get install git
sudo apt-get install code

실행
arlt + F2 : code

2. 언어 설정
2.1 인터페이스 검색
검색 : ctrl + shipt + p
입력 : display
변경 : "local": "en" -> "ko"
적용 : clrs + s

2.2 인터페이스 한글 저장소 패키지 다운로드
검색 : ctrl + shipt + x
입력 : korea language pack
변경 : install 클릭
적용 : reset now 클릭

2.3 사용할 언어 문법 강조 패키지 다운로드
검색 : ctrl + p
입력 : ext install c/c++
선택 : c/c++ IntelliSense, debugging, and code bro....
적용 : 다시로드

2.4 MinGW 문법 강조(리눅스에서 윈도우 프로그램)
2.4.1 구성
- 리눅스 파티션에 윈도우 설치
- 윈도우 개발환경 구성
- 리눅스 부팅후 마운팅
- apt-get install g++-mingw-w64 mingw-w64 ---> 상항에 맞게 설치

검색 : ctrl + shift + p
입력 : c/pp
선택 : c/cpp: edit configurations...
변경 :
a) 이동: 프로젝트 .vscode 디렉토리
b) 확인: vi c_cpp_propertiess.json
c) 검색: /compilePath
d) 설명: https://github.com/Microsoft/vscode-cpptools/blob/master/Documentation/LanguageServer/MinGW.md
e) 설정:
{

    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceRoot}",
                "mount_driver_C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++",
                "mount_driver_C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/mingw32",
                "mount_driver_C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/backward",
                "mount_driver_C:/MinGW/include",
                "mount_driver_C:/MinGW/lib/gcc/mingw32/6.3.0/include-fixed",
                "mount_driver_C:/MinGW/lib/gcc/mingw32/6.3.0/include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "__GNUC__=6",
                "__cdecl=__attribute__((__cdecl__))"
            ],
            "intelliSenseMode": "clang-x64",
            "browse": {
                "path": [
                    "${workspaceRoot}",
                    "mount_driver_C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++",
                    "mount_driver_C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/mingw32",
                    "mount_driver_C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/backward",
                    "mount_driver_C:/MinGW/include",
                    "mount_driver_C:/MinGW/lib/gcc/mingw32/6.3.0/include-fixed",
                    "mount_driver_C:/MinGW/lib/gcc/mingw32/6.3.0/include"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        }
    ],
    "version": 4
}
f) 다시로드

3. 프로젝트 생성
3.1 프로젝트 위치 지정
검색 : ctrl + shift + e (탐색기 창)
열기 : ctrl + k, ctrl + o
생성 : 디렉토로 만들기(아이콘 클릭) 생성

3.2 디렉토리 생성
검색 : 오른쪽 패널창 -> 디렉토리 아이콘 생성 클릭
입력 : 디렉토리 이름

3.2.1 추가
영역 : 생성할 디렉토리 빈 공간 영역 선택
검색 : 오른쪽 패널창 -> 디렉토리 아이콘 생성 클릭
입력 : 디렉토리 이름

3.3 파일 생성
검색 : 오른쪽 패널창 -> 파일 아이콘 생성 클릭
입력 : 파일 이름



4. 컴파일
4.1 빌드 환경 구성
이동: 오른쪽 패널창 -> .vscode::{} tasks.json
입력: tasks.json
수정:
{
    "version": "2.0.0",
    "runner": "terminal",
    "type": "shell",
    "echoCommand": true,
    "presentation" : { "reveal": "always" },
    "tasks": [
          // g++ compile
          {
            "label": "save and compile for C++",
            "command": "g++",
            "args": [
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "group": "build",

            // compile error editer apply
            // reference:   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
                }
            }
        },
        //gcc compile
        {
            "label": "save and compile for C",
            "command": "gcc",
            "args": [
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "group": "build",

            // compile error editer apply
            // reference:   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
                }
            }
        },
        // linux binary execution

        {
            "label": "execute",
            "command": "cd ${fileDirname} && ./${fileBasenameNoExtension}",
            "group": "test"
        }
        // // windows binary execution
        // {
        //     "label": "execute",
        //     "command": "cmd",
        //     "group": "test",
        //     "args": [
        //         "/C", "${fileDirname}\\${fileBasenameNoExtension}"
        //     ]
 
        // }
    ]
}
4.2 단축키 설정
선택: 파일 > 기본 설정 > 바로 가기 키
이동: 오른쪽 패널창 -> 열려 있는 편집기 -> Keyboard Shortcuts
입력: 고급 사용자 지정의 경우 다음 파일을 열고 편집하세요. keybinding.json <- 클릭
우선 순위: 1. 사용자 환경 단축키 
           2. 기본 제공 단축키 설정

// Place your key bindings in this file to override the defaults
[
// compile
    { "key": "ctrl+alt+c", "command": "workbench.action.tasks.build" },
 
    // execute
    { "key": "ctrl+alt+r", "command": "workbench.action.tasks.test" }
]

단축키 : Ctrl +Alt + C
컴파일: save and compile for C
확인: 오른쪽 패널창 컴파일 결과 파일 생성
실행: Ctrl  + Alt + R -> execute

5. 디버깅
이동: 오른쪽 패널창 -> .vscode::{} tasks.json
입력: tasks.json
수정:
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "runner": "terminal",
    "type": "shell",
    "echoCommand": true,
    "presentation" : { "reveal": "always" },
    "tasks": [
          // g++ compile
          {
            "label": "save and compile for C++",
            "command": "g++",
            "args": [
                "${file}",
                "-g",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "group": "build",

            // compile error editer apply
            // reference:   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
                }
            }
        },
        //gcc compile
        {
            "label": "save and compile for C",
            "command": "gcc",
            "args": [
                "${file}",
                "-g",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "group": "build",

            // compile error editer apply
            // reference:   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
                }
            }
        },
        // linux binary execution

        {
            "label": "execute",
            "command": "cd ${fileDirname} && ./${fileBasenameNoExtension}",
            "group": "test"
        }
        // // windows binary execution
        // {
        //     "label": "execute",
        //     "command": "cmd",
        //     "group": "test",
        //     "args": [
        //         "/C", "${fileDirname}\\${fileBasenameNoExtension}"
        //     ]
 
        // }
    ]
}

선택: 오른쪽 패널창 -> 디버그 아이콘 클릭
이동: 환경설정 아이콘 클릭 -> 사용할 GDB 선택
수정: launch.json
{
    // IntelliSense를 사용하여 가능한 특성에 대해 알아보세요.
    // 기존 특성에 대한 설명을 보려면 가리킵니다.
    // 자세한 내용을 보려면 https://go.microsoft.com/fwlink/?linkid=830387을(를) 방문하세요.
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            // "program": "enter program name, for example ${workspaceFolder}/a.out",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            //"externalConsole": true,
            "externalConsole": false,
            "MIMode": "gdb",
            // windows gdb
            // "miDebuggerPath": "C:/MinGW/bin/gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]

적용: 비쥬얼 스튜디오 디시 시작

참고:
윈도우에서 사용하는 디버깅 창 및 단축키,
비주얼 스튜디오 버전마다 단축키 차이가 있음.

자동/조사식/메모리 창
자동창 생성: 디버그 -> 창 -> 자동
단축키 : ctrl + alt + v, a

조사식창 생성: 디버그 -> 창 -> 조사식 -> 조사식 1~4
단축키 : ctrl + alt + w, 1~4
Shift+F9: 다른 창을 띄워서 변수의 값이 얼마인지 계산할 수있고, 그 자리에서 조사식을 추가 할 수도 있다.

메모리창 생성: 디버그 -> 메모리 -> 메모리 1~4
단축키 : ctrl + alt + m, 1~4
기본 메모리 창 : alt + 6

F9 : 브레이크 포인트 설정 및 해제

전체 브레이크 포인트 해제 : 디버그 -> 모든 중단점 해제
단축키 : Ctrl + Shift + F9

F5 : 디버깅 연결 프로그램과 시작.
Shift + F5 : 디버깅 없이 실행

F10: 디버깅 모드에서 한줄씩 코드를 진행하되, 다른 함수를 호출하게 되는 경우에 그 프로시저를 모두 실행하고 원래 코드로 돌아와서 한줄을 실행하는 기능
Ctrl + F10 : 커서까지 실행, 디버깅 모드에서 커서가 위치한 줄을 만날때 까지 실행하는 기능
Shift + F10 : 프로시저 나가기

F11: 한줄씩 실행
Shift + F11: 프로시저 나가기, 디버깅 모드에서 현재 현재 프로시저의 나머지를 모두 실행하고 나가는 기능

디버깅 공식
1) 중단점을 설정한다.
2) 디버깅 시작
3) F11 을 누르며 한단계씩 코드 실행 or  F10 으로 프로시저 단위 실행
4) 조사식을 추가하여 변수의 변화를 살펴본다.

함수 추적시.
stdio.h, iostream 라이브러리 호출 부분으로 진입시.
Shift + F10 : 프로시저 나가기

댓글 없음:

댓글 쓰기