我有一个项目结构像这样:跨编译使用GNU不同的目录,使
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
所以在这里我的目标是编译测试MCTS /测试/ list_test.c。我已经阅读了几个不同的策略来做到这一点。读了一下后,我适应一些事情我从Makefile文件到这一点:
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 [email protected] list_test.o munit.o ../src/node_queue.o
.c.o:
$(CC) $(CFLAGS) -c $< -o [email protected]
这是我在约2小时读懂了工作,调用mcts/tests
make
当最接近我收到错误:
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
其中构建在mcts/src/node_queue.h
中定义。 不应该$(INCLUDE)
确保包含标题? 我怎样才能得到这个功能?
非常感谢!
首先,你不需要'.co'规则 - Make有内置的。 – Novelocrat
其次,最好使用'VPATH'来指定你想要的目录搜索对象,而不是烘焙路径进入你的依赖和命令。即你会说'list_test:list_test.o munit.o node_queue.o',然后规则会运行带有参数'-o $ @ $ ^'的命令来告诉它仅仅引用所有的依赖关系,无论它在哪里找到它们。 – Novelocrat
@Novelocrat我正在研究'VPATH',但正在阅读[this](http://make.mad-scientist.net/papers/how-not-to-use-vpath/),这看起来好像更好尝试其他方法。 –