MacOS의 vscode에서 C++ 코드를 디버깅하려고 합니다.

MacOS의 vscode에서 C++ 코드를 디버깅하려고 합니다.

MacOS의 VSCode에서 C++17 코드를 디버깅하려고 하는데 VSCode 명령줄을 통해 빌드할 수 있지만 디버그를 빌드하려고 하면 다음 오류가 발생합니다.

오류

C++17 코드를 빌드하기 위해 VSCode에서 시작 및 작업 JSON 파일을 구성하는 방법은 무엇입니까? 또한 C++20의 공동 루틴 코드를 컴파일하고 싶습니다. VSCode에서 어떻게 동일한 빌드를 할 수 있나요?

답변1

C++를 지원하는 IDE를 설치합니다. Visual Studio Code는 모든 기능을 갖춘 코드 편집기이지만 Visual Studio와 같은 IDE는 아닙니다. C++를 지원하는 일반적으로 사용되는 IDE라면 모두 가능합니다. XCode는 C++ 컴파일러가 내장된 매우 깔끔한 IDE이므로 클릭 한 번으로 C++를 작성하고 컴파일하고 실행할 수 있습니다.

답변2

아래 구성을 사용하여 MacOS의 VSCODE에서 C++17 코드를 빌드할 수 있습니다.

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "clang++ build active file",
            "command": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++",
            "args": [
                "-g",
                "${file}",
                "-std=c++17",
                "--debug",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin"
            },
            "problemMatcher": [
                "$gcc"
            ]
        }
    ]
}

답변3

macOS의 VSCode에서 C++ 코드를 빌드하고 디버그하려면 다음을 따라야 합니다.이 튜토리얼

그러면 c_cpp_properties.json(프로젝트 폴더의 .vscode 폴더 내)은 다음과 같아야 합니다(YOURUSERNAME을 macOS 사용자 이름으로 대체).

{
"configurations": [
    {
        "name": "Mac",
        "includePath": [
            "${workspaceFolder}/**",
            "/Users/YOURUSERNAME/bin/CPP_Libraries/Eigen/Eigen/**"
        ],
        "defines": [],
        "macFrameworkPath": ["/System/Library/Frameworks",
            "/Library/Frameworks"],
        "compilerPath": "/usr/bin/clang",
        "cStandard": "c11",
        "cppStandard": "c++17",
        "intelliSenseMode": "clang-x64"
    }
],
"version": 4

}

관련 정보