'How can I resolve clang input unused in multiple indirection Makefile?

I'm trying to write a makefile that will enable a test suite runner, test.c, to run. However, I think my use of the -c flag is getting in the way.

all: parser

parser_out.o: parser_out.h parser_out.c
    clang -c -g parser_out.c
    
parser_loader.o: parser_loader.h parser_loader.c parser_mem.o
    clang -c -g lc4_mem.o parser_loader.c
    
parser_mem.o: parser_mem.h parser_mem.c
    clang -c -g parser_mem.c

parser: parser.c parser_mem.o parser_loader.o parser_out.o
    clang parser.c -g parser_mem.o parser_loader.o parser_out.o -o parser

tests: test

test_helpers.o: test_helpers.c test_helpers.h
    clang test_helpers.c -c -g

parser_loader.test.o: parser_loader.test.h parser_loader.test.c parser_loader.o test_helpers.o
    clang parser_loader.test.c -g parser_loader.o test_helpers.o

test: test.c parser_loader.test.o
    clang test.c -g parser_loader.test.o -o test

make all works as expected.

make tests fails and indicates that references to methods in parser_mem.c are undefined.

make parser_loader.test.o results in the same error as make tests.

If I include parser_mem.o directly in the linking of parser_loader.test.o, the errors caused by linking to my files disappear. But, an error indicating invalid linking to GNU remains:

/usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
  1. Why aren't my references through references being handled successfully?
  2. Why is clang suddenly struggling to compile with system links?


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source