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