使用VSCode

前言

听说vscode好,我也尝试了下。

mingw w64

好像在windows中,mingw w64mingw好,既可以编译32位的程序,又可以编译64位的。
离线包的地址
我选择的x86_64-posix-seh

安装好之后,windows下需要设置环境变量

  • Path(将mingw64下bin包含进path变量中)
  • C_INCLUDE_PATH(一般需要新建这个变量,值为mingw下的include文件夹,x86_64-w64-mingw32文件夹下好像也有include文件夹,不过我没用),
  • CPLUS_INCLUDE_PATH(同上)。

设置完之后,最后重启。
linux不用自己设置这些变量。

vscode

vscode中需要打开文件夹,才能配置相关的文件。
需要在文件夹下创建 .vscode文件夹,其中包含3个文件

  • tasks.json
  • launch.json
  • c_cpp_properties.json

tasks.json

tasks.json是关于任务的配置文件,可以把编译当做一种任务。

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "cpp_compile",
            "type": "shell",
            "windows": {
                "command": "g++",
                "args": [
                    "-g", "${file}", "-o",
                    "${fileDirname}\\${fileBasenameNoExtension}.exe"
                ]
            },
            "linux": {
                "command": "g++",
                "args": [
                    "-g", "${file}", "-o",
                    "${fileDirname}/${fileBasenameNoExtension}.out"
                ]
            },
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

launch.json

launch.json是关于debug的配置文件。

{
    // 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",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": true,
            "program": "", // Defining "program" in here just is prevent report "Missing property "program"".
            //Properties defined in an operating system specific scope override properties defined in the global scope.
            "windows": {  
                "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "MIMode": "gdb",
                "miDebuggerPath": "gdb.exe",
                //"miDebuggerPath": "D:\\ProgramData\\mingw64\\bin\\gdb.exe",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ],
            },
            "linux": {
                "program": "${fileDirname}/${fileBasenameNoExtension}.out",
                "MIMode": "gdb",
                "miDebuggerPath": "/usr/bin/gdb",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ],
            },
           "preLaunchTask": "cpp_compile"
        },

        {
            "name": "Python: Current File (Integrated Terminal)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "stopOnEntry": true
        },
        {
            "name": "Python: Attach",
            "type": "python",
            "request": "attach",
            "port": 5678,
            "host": "localhost"
        },
        {
            "name": "Python: Module",
            "type": "python",
            "request": "launch",
            "module": "enter-your-module-name-here",
            "console": "integratedTerminal"
        },
        {
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/manage.py",
            "console": "integratedTerminal",
            "args": [
                "runserver",
                "--noreload",
                "--nothreading"
            ],
            "django": true
        },
        {
            "name": "Python: Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "app.py"
            },
            "args": [
                "run",
                "--no-debugger",
                "--no-reload"
            ],
            "jinja": true
        },
        {
            "name": "Python: Current File (External Terminal)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "externalTerminal"
        }
    ]
}

c_cpp_properties.json

关于IntelliSense的配置文件,貌似自动最近的vscode自动配置好了

vscode插件

  • code-settings-sync
  • Vim
  • C/C++
  • Python

猜你喜欢

转载自blog.csdn.net/Tifa_Best/article/details/83153988