Reputation: 11
I have a project structure like such:
mcts/
src/
node_queue.c
node_queue.h
tests/
munit.c # testing frame work
munit.h
list_test.c # includes node_queue.h and munit.h
Makefile # Makefile in question
So my objective here is to compile the test mcts/test/list_test.c . I have read a couple different strategies to doing this. After reading a bit I adapted some things I took from Makefiles into this:
CC= gcc
SOURCE= $(wildcard ../src/*.c ./*.c)
OBJECTS= $(patsubst %.c, %.o, $(SOURCE))
INCLUDE= -I. -I../src/
CFLAGS= -std=c11 -g $(INCLUDE) -Werror -Wall
list_test: list_test.o munit.o ../src/node_queue.o
$(CC) $(CFLAGS) $(INCLUDE) -o $@ list_test.o munit.o ../src/node_queue.o
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
Which is the closest I've gotten in about 2 hours to working, when calling make
in mcts/tests
I receive the error:
list_test.o: In function `construct_test':
/home/----/mcts/tests/list_test.c:9: undefined reference to `construct'
collect2: error: ld returned 1 exit status
make: *** [Makefile:8: list_test] Error 1
Where construct is defined in mcts/src/node_queue.h
.
Shouldn't $(INCLUDE)
ensure that the header is being included?
And how can I get this to function?
Much thanks!
Upvotes: 0
Views: 55
Reputation: 38138
For your actual error, you're reporting a linking error to an undefined symbol. If the object or function of that name were defined in node_queue.h
, you would instead get a multiple definition error for construct
.
What you probably are missing is that you have a declaration in that header, but no definition in node_queue.c
.
Upvotes: 1