C - How to run the debugger for tests with VS Code?

Hi all,

Hopefully anyone can guide me in the right direction on how to use the debugger in VS Code for C. The make test command works perfectly fine, but I am new to C and would love to use the debugger to step through the code line by line.

Running the test file in VS Code (for the grade school exercise in this example) results in the following error on a MacBook Pro 2019:

ld: Undefined symbols:
  _UnityAssertEqualNumber, referenced from:
      _test_roster_is_empty_when_no_student_added in test_grade_school-90dee8.o
      _check_rosters in test_grade_school-90dee8.o
  _UnityAssertEqualString, referenced from:
      _check_roster_names in test_grade_school-90dee8.o
.... (bunch of tracebacks)
      _test_student_not_added_to_same_grade_in_roster_more_than_once in test_grade_school-f301fd.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
➜  grade-school 

Any idea what I am doing wrong? Any feedback is very much appreciated!

Hi! You could try using an IDE instead of VSC. One of my teachers once said that VSC is actually a text editor with a bunch of plugins. Writing code then compiling it is easier and less messy with an IDE. You could try CodeBlocks or Eclipse (if you’re using linux, i do not recommend using it on Windows) along with a compiler such as gcc and gdb to do some debug. With these tools you should be good to go.

Hope it helps!

That sounds like you’re describing a modular IDE!

Thanks for the tips. I am trying the “C Unity Test Explorer” plugin and I am getting a little closer. If I can’t get that to work, I’m going to try CodeBlocks or Eclipse!