2016-08-03 33 views
0

我有一个项目结构像这样:跨编译使用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/testsmake当最接近我收到错误:

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)确保包含标题? 我怎样才能得到这个功能?

非常感谢!

+0

首先,你不需要'.co'规则 - Make有内置的。 – Novelocrat

+0

其次,最好使用'VPATH'来指定你想要的目录搜索对象,而不是烘焙路径进入你的依赖和命令。即你会说'list_test:list_test.o munit.o node_queue.o',然后规则会运行带有参数'-o $ @ $ ^'的命令来告诉它仅仅引用所有的依赖关系,无论它在哪里找到它们。 – Novelocrat

+0

@Novelocrat我正在研究'VPATH',但正在阅读[this](http://make.mad-scientist.net/papers/how-not-to-use-vpath/),这看起来好像更好尝试其他方法。 –

回答

1

对于您的实际错误,您正在向未定义的符号报告链接错误。如果在node_queue.h中定义了该名称的对象或功能,则您将改为为construct获取多重定义错误。

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

+0

是的,我刚刚失去了5个小时拼写建设作为contsruct ...但我确实有我的Makefile现在的顺序 [gist](https://gist.githubusercontent.com/Beaudidly/b374790854a91f2e3f3f1c077381c571/raw/2c1488010ebc7d3c11b26bf34add51c63e04da25/Makefile) –

+0

它发生在我们所有人身上。 – Novelocrat

相关问题