天天看點

VSCode + CMakeList

1、下載下傳安裝VSCode

2、配置CMakeList可以執行檔案,格式如下

cmake_minimum_required(VERSION 3.16)
project(test)

set(CMAKE_CXX_STANDARD 14)

add_executable(test main.cpp)
           

3、設定配置launch.json(選擇左邊的小之主,然後生成新的json的檔案,選擇c++(GDB/LLDB),然後就會自動生成launch.json檔案,把"program": "enter program name, for example ${workspaceFolder}/a.out"改成你的可執行檔案,如下所示),

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/project",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}
           

4、編譯ctrl+shift+p,選擇cmake build編譯選擇gcc編譯器,然後就可以生成可執行檔案

然後F5就可以調試了。

繼續閱讀