用GNU make编译不同的目录

时间:2016-08-03 14:09:43

标签: c unit-testing makefile gnu-make

我有一个像这样的项目结构:

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 / test / list_test.c。我已经阅读了几种不同的策略来做到这一点。在阅读了一下之后,我将从Makefiles中取出的一些内容改编为:

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 $@

我在约{2}中拨打make时距离工作约2小时内最接近的是我收到错误:

mcts/tests

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不应该确保包含标题吗? 我怎样才能让它发挥作用?

非常感谢!

1 个答案:

答案 0 :(得分:1)

对于您的实际错误,您需要向未定义的符号报告链接错误。如果node_queue.h中定义了该名称的对象或函数,则会为construct获取多个定义错误。

您可能缺少的是您在该标题中有声明,但在node_queue.c中没有定义。

相关问题