Ex30: How to properly include dbg.h in minunit.h

Including dbg.h in minunit.h with #include <dbg.h> as shown in the book results in a compiler error for me.

It works if I have dbg.h in both folders (src and tests) and do #include "dbg.h". But having the same file twice in different locations can’t be the solution, can it?


And a second question about minunit.h: Is there a specific reason for not declaring tests_run in the mu_suite_start macro too?

I suddenly realised that the answer to the second question is pretty obvious: It’s about scope. If I declare tests_run in mu_suite_start then it won’t be visible to the main that runs the tests, because mu_suite_start will be called inside another function.

Just to let you know that I solved the first problem, too. It looks like I need to run gcc from the root directory of the project. Kinda makes sense…


About ex32:
Maybe it’s worth pointing out that you need to list library archives after the source files that require them with gcc? – The line tests: CFLAGS += $(TARGET) in the Makefile doesn’t work with gcc, I had to define my own recipe:

$(TESTS):
    $(CC) $(CFLAGS) -o $@ $(patsubst %,%.c,$@) $(TARGET)

.PHONY: tests
tests: $(TESTS)
    sh .tests/runtests.sh

It’s awkward because I’m transforming the path to the single test executable back into the path to its source file – I can’t just put the whole $(TEST_SRC) there. Does anybody have a better solution?

Well, you did write that we might have to swap things around.

A free service run by Zed A. Shaw for learncodethehardway.org.