코딩 공부/TIL(Today I Learn)

VSC C++ 셋팅 메모 (+ Thread가 안될때)

메카인 2023. 9. 18. 18:58

Unreal Engine에서 자신들의 컴파일러(VS framework)를 통해서 컴파일 하게 되는데, 이때 편집기로 VSC를 사용하니 이후 일반 cpp 파일이 컴파일이 되지 않아 확인하며 쓴 글이다.

컴파일이 되지 않았던 이유는 컴파일러 셋팅과 단축키 셋팅이 있는 폴더(워크 스페이스)에서 컴파일 하지 않았기 때문이다. (기존 C++ 폴더가 워크스페이스로 지정되지 않고 Unreal Engine Project 폴더로 지정되어 있었다)

워크 스페이스(폴더)에 사용자가 셋팅 해놓은 .vscode 폴더(task.json etc)를 통해 컴파일 및 빌드, 단축키와 같은 설정을 할 수 있다.

 

+ 추가) Thread가 실행이 되지 않아 해결 방법을 찾던중 기존 mingw를 삭제하고 msys를 설치하여 해결하였다. 따라서 컴파일러 세팅 부분을 msys를 설치로 대체하고 vs code 세팅을 하는 것을 추천한다.

 

+ 추가) 현재는 gpt가 추천한 방식으로 전환하여 ctrl + shift + b로 컴파일을 하고 있다.

 

 

msys 설치 및 세팅

https://jhnyang.tistory.com/445

 

세팅 방법

https://y-oni.tistory.com/182#toc231

 

VSCode에서 C언어와 C++ 코딩 환경 세팅하기

[Leaves][리브스] 스마트 디밍 노트북 라이트 / 랩탑 조명 nefing.com VSC에서 C/C++ 코딩환경 세팅하기 VSC에서 C 언어 및 C++ 코딩을 하기 위한 개발환경 세팅방법입니다. VSC에서 C/C++을 사용하려면 크게

y-oni.tistory.com

세팅 방법 및 문제시 해결 방법

https://rasino.tistory.com/307

 

【 C 환경설정 】 VS code에서 C/C++ 코딩환경 구축하기

【 C 환경설정 】 VS code에서 C/C++ 코딩 환경 구축하기 요즘 파이썬(python)이나 자바(JAVA), javascript C# 등등 하이레벨 언어를 학습하던 사람들이 프로그래밍의 근간을 튼튼히 한다거나? 여러 가지 이

rasino.tistory.com

 

mingw64 삭제하는 법

https://www.youtube.com/watch?v=WWSK8wYvs2w&list=LL&index=5&t=213s 

 

MinGW download

https://sourceforge.net/projects/mingw/files/

 

C/C++ task.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
                }
            }
        },
        // // 바이너리 실행(Windows)
        {
            "label": "execute",
            "command": "cmd",
            "group": "test",
            "args": [
                "/C",
                "${fileDirname}\\${fileBasenameNoExtension}"
            ]
        }
    ]
}

 

 keybindings.json 

// Place your key bindings in this file to override the defaults
// 아래 키 바인딩을 파일에 넣어서 기본값을 덮어 씁니다.


[
    // 컴파일
    {
        "key": "ctrl+alt+c",
        "command": "workbench.action.tasks.build"
    },
    // 실행
    {
        "key": "ctrl+alt+r",
        "command": "workbench.action.tasks.test"
    }
]