Linux learning record. 6.vscode Debug C Makefile

Source: Internet
Author: User

Reference

Https://www.cnblogs.com/lidabo/p/5888997.html

The task has an update and cannot use the code of the article.

Multiple files

Terminal

Touch MAIN.C hw.c hw.h

Vscode hw.c

Vscode

Open Folder

Preparation of three project files

1 /* hw.c */ 2 " hw.h " 3 4 void print () 5 {6     printf ("Hello world!\n"); 7 }

1 /* hw.h */ 2 #include <stdio.h>34void print ();

1 /* main.c */ 2 " hw.h " 3 4 int Main () 5 {6    print (); 7 8     return 0 ; 9 }

Use this

Using GCC directly at the terminal

GCC main.c hw.c hw.h

Generate A.out and HW.H.GCH

Use make

Build Makefile Touch makefile under the project directory

Writing makefile Files

build:main.o hw.o      -o build main.o hw.omain.o:main.c hw.h    -G-c main.chw.o:hw.c    hw.h-G-C Hw.cclean:     

The code under Ps:clean needs to use make clean to call

-G: Debug using

-C: Compile only (Compile), do not connect (make)

-o: Output file name

VS Code Debug Configuration

{    /*Launch.json*/    //use IntelliSense to understand related properties. //hover to view the description of an existing property. //For more information, please visit:https://go.microsoft.com/fwlink/?linkid=830387    "version":"0.2.0",    "configurations": [        {             "name":"(GDB) Attach",            "type":"cppdbg",            "Request":"Attach",            " Program":"${workspacefolder}/build",            "processId":"${command:pickprocess}",            "Mimode":"gdb",            "Setupcommands": [                {                    "Description":"Enable pretty-printing for GDB",                    "text":"-enable-pretty-printing",                    "Ignorefailures":true                }            ]        },        {            "name":"(GDB) Launch",            "type":"cppdbg",            "Request":"Launch",            " Program":"${workspacefolder}/build",            "args": [],            "Stopatentry":false,            "CWD":"${workspacefolder}",            "Environment": [],            "Externalconsole":true,            "Mimode":"gdb",            "Setupcommands": [                {                    "Description":"Enable pretty-printing for GDB",                    "text":"-enable-pretty-printing",                    "Ignorefailures":true                }            ],                        "Prelaunchtask":" Make"    //Add                    }    ]}
{    /*Task.json*/    // Seehttps://go.microsoft.com/fwlink/?LinkId=733558    //For the documentation about the Tasks.json format    "version":"2.0.0",    "Tasks": [        {            "label":" Make",            "type":"Shell",            "Command":" Make",            "args": []                    }            ]}

CTRL + SHIFT + B compilation

Set breakpoints

F5 Start debugging

The popup terminal displays the output.

Linux learning record. 6.vscode Debug C Makefile

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.