VS Code and multiple files (libraries)

Hello.
I setup VS Code to work with gcc and gdb (Windows 11 with mingw64). The compile and debug with 1 file works fine.
Now, how do I setup the tasks.json and launch.json to compile multiple files and
debug the project? So that I can use the GUI from VS Code for debugging.

I have these files:
 
main.c lib.c lib.h.


When I compile and use gdb on the terminal all works fine:
1
2
3
gcc -g -shared lib.c -o lib.a -l:libshlwapi.a -l:libversion.a
gcc -g main.c -L./ -l:lib.a -o main.exe
gdb main.exe


How do you put these commands into VS Code to compile/debug the project?

My tasks.json:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{
   "tasks": [
      {
         "type": "cppbuild",
         "label": "gcc.exe build_and_debug",
         "command": "D:\\mingw64\\bin\\gcc.exe",
         "args": [
            "-g",
            "-Wall",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
         ],
         "options": {
            "cwd": "${cwd}"
         },
         "problemMatcher": [
            {
               "base": "$gcc",
               "fileLocation": [
                  "absolute"
               ]
            }
         ],
         "group": {
            "kind": "build",
            "isDefault": true
         },
         "detail": "Generated task by Debugger"
      },
   ],
   "version": "2.0.0"
}


My launch.json:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
   "version": "0.2.0",
   "configurations": [
      {
         "name": "gcc.exe - Build and debug active file",
         "type": "cppdbg",
         "request": "launch",
         "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
         "args": [],
         "stopAtEntry": false,
         "cwd": "${workspaceFolder}",
         "environment": [],
         "externalConsole": false,
         "MIMode": "gdb",
         "miDebuggerPath": "D:\\mingw64\\bin\\gdb.exe",
         "setupCommands": [
            {
               "description": "Enable pretty-printing for gdb",
               "text": "-enable-pretty-printing",
               "ignoreFailures": true
            }
         ],
         "preLaunchTask": "gcc.exe build_and_debug"
      }
   ]
}


Thank you.



Last edited on
Topic archived. No new replies allowed.