Vscode uses makefile to debug and run C/C++ programs online

1 Introduction

     In the previous article, the method of debugging C/C++ programs online in vscode introduced the method of debugging programs. Since the compiler rules used in the article are implemented by calling task.json, they are not applicable to general programs. At present, most programs use makefile to compile and debug. This article will introduce the method of using vscode to call makefile to realize program compilation, and finally to realize program debugging.

2. Project preparation

       Prepare a project that can be compiled through make. The project still uses the project in the previous article, as shown in the figure below. The project contains main.c, bch.c, node_auth.c, sensor_auth.c and linked library files.

3. Project settings 

       This project can be compiled directly using make, so it can also be compiled by calling make in vscode. The calling method is to modify the task.json file.

    Since online debugging is required, the generated target file must have debugging information, so add -g to the Makefile to output debugging information. In this project, external parameters are used to control make. The Makefile is modified as follows.

 

      During online debugging, vscode will call launch.json to start debugging, so you need to set the target file generated by compilation. The target file generated by compiling this project is auth, so you need to modify lauch.json to call the target file auth.

4. Start debugging

     The above settings for the project have been completed, open the main.c file at the entrance of the program, and click the debug "C/C++ file" button to enter the debugging interface.

 

         Enter the debugging interface, as shown in the figure below.

 

5. Makefile plug-in debugging

     If the makefile plugin is installed in vscode. You can also use makefile to compile and debug, please explore by yourself.

 

Guess you like

Origin blog.csdn.net/fhqlongteng/article/details/127388105