Mac system vscode configuration c/c++ environment

Mac system vscode configuration c/c++ environment

This article introduces the installation of vscode under the mac system and the configuration of the c environment;

Features of this article:

1. You can display the running results of the c program in the terminal that comes with vscode.

2. When debugging the c program, parameters need to be input in the program, which can be input directly in the terminal that comes with vscode.

Reference article: https://zhuanlan.zhihu.com/p/103308900

1.  Download vscode and install it

Download the installation package suitable for your system on the vscode official website

Then enter the xcode-select --install command in the terminal that comes with the mac, and install the Xcode tool according to the prompts.

2.  Install the necessary plug-ins ( 4 )

Click on the menu bar on the right side of the application

 

c/c++ (required)

Chinese (Chinese plug-in)

Code Runner (required)

CodeLLDB (code debugging) ps. When debugging the program without installing this plug-in, you cannot enter parameters in the terminal that comes with vscode

3.  Create a new folder and open it in the app

new folder code

Open the code folder in the top menu bar of the application

 

Create a new test.c file under the code folder

Randomly type a piece of c code in test.c

Click on the small gear in the upper right corner

Choose to click C/C++: gcc or C/C++: clang

The launch.json and tasks.json files will be added automatically

And automatically open the launch.json file

4. Configure launch.json and tasks.json files

Replace the content in launch.json with the following code

{

    "version": "0.2.0",

    "configurations": [

        {

            "type": "lldb",

            "request": "launch",

            "name": "Debug",

            //"program": "${workspaceFolder}/test.out",

            //上一行是官方写法,但是不同的cpp调试都要改配置,非常麻烦

            "program": "${workspaceFolder}/${fileBasenameNoExtension}",

            "args": [],

            "cwd": "${workspaceFolder}",

            "preLaunchTask": "Build with Clang"

        }

    ]

}

Click on the tasks.json folder and copy the content behind lable

 Paste the content just copied to the preLaunchTask of the launch.json file

 At this point, the launch.json and tasks.json files have been configured

5. Run the program in the terminal integrated with vscode

Click Run Code to run the program, and the program will run in the built-in terminal.

6.  Debugging program

Do not directly use "Debug C/C++ Files" in the upper right corner, use the debug in the left menu bar

 During the debugging process, if the program needs input, it can be input directly in the terminal integrated with vscode. END

Guess you like

Origin blog.csdn.net/richard847/article/details/129131227