2012-06-14 58 views
0

我目前正在编写一个简短的测试应用程序。 编译给了我这些错误:目标文件缺失函数符号

CC main.c 
Building ../bin/pmono 
./main.o:(.data+0x18): undefined reference to `busy' 
./main.o:(.data+0x58): undefined reference to `busy' 
./main.o:(.data+0x98): undefined reference to `busy' 
./main.o:(.data+0xd8): undefined reference to `busy' 
./main.o:(.data+0x118): undefined reference to `busy' 
./main.o:(.data+0x158): more undefined references to `busy' follow 
collect2: ld a retourné 1 code d'état d'exécution 

我会尽量向下缩小代码的特定部分。

这里是一个结构Ⅰ使用含有所期望的参考:

/* 
* Chained list of blocks from a frame of the cyclic executive 
*/ 
typedef struct block { 
    long c;     /* Worst case execution time */ 
    long d;     /* Deadline */ 
    long p;     /* Period */ 
    void (*action) (long);  /* Action performed by this frame */ 
    struct block * next;  
} *Frame; 

函数指针是占位符的通用功能尚未写入,宣布为在相同的h文件:

/* 
* Load the CPU for a determined time expressed in nanosecond 
*/ 
void busy(long t); 

这个功能目前在C文件中空心:

void busy(long t) { 
} 

最后,这里是一个样本默认结构我在我的测试中使用:

struct block D = {8,20,20,busy,0}; 
struct block C = {2,20,20,busy,&D}; 
struct block B = {3,10,10,busy,&C}; 
struct block A = {1,10,10,busy,&B}; 
Frame sequence0 = &A; 

所有这些部件都包含在周期性任务众多实施之间共享一个共同的源文件。目标文件的编译看起来很好。 当我尝试编译给定的实现时,首先包含.h文件,编译.o文件,然后尝试使用makefile链接整个事物。下面是一个makefile来给你一个想法:

BIN = ../bin/pmono 
CC = gcc 

SUBDIR = . 
SRC = $(foreach dir, $(SUBDIR), $(wildcard $(dir)/*.c)) 
OBJ = $(SRC:.c=.o) $(wildcard ../common/*.o) 
INCLUDES = 
WARNINGS = 
OPTIMISATION = 
DEBUG = 

XENO_CONFIG = /usr/xenomai/bin/xeno-config 
XENO_POSIX_CFLAGS = $(shell $(XENO_CONFIG) --skin=posix --cflags) 
XENO_POSIX_LDFLAGS = $(shell $(XENO_CONFIG) --skin=posix --ldflags) 

CFLAGS = $(INCLUDES) $(XENO_POSIX_CFLAGS) $(WARNINGS) $(OPTIMISATION) 
LDFLAGS = -lm $(XENO_POSIX_LDFLAGS) $(DEBUG) 

all:.depend $(BIN) 

%.o:%.c 
    @echo "CC $<" 
    @$(CC) -c $(CFLAGS) $< -o [email protected] 

$(BIN): $(OBJ) 
    @echo "Building ${BIN}" 
    @$(CC) $(OBJ) -o [email protected] $(LDFLAGS) 

clean: 
    rm -f $(OBJ) 

distclean: clean 
    rm -f $(BIN) 
    rm -f ./.depend 

.depend: $(SRC) 
    @echo "Génération des dépendances" 
    @$(CC) $(CFLAGS) -MM $(SRC) > .depend 

-include .depend 

所以,我在这个初学者,这是我的理解:忙功能的符号在main.o丢失,而它的存在在cyclic_executive.o文件中。我不明白这是如何可能的,因为我包含了cyclic_executive.h文件,从而给出了正确的声明和原型。

我觉得我做错了,但我的想法很短。 另外,我真的不喜欢我如何声明我的“默认”序列。我知道有一个正确的方法来做到这一点,但我不记得它...有人有一个名字来帮助搜索它吗?

谢谢。

+0

你似乎没有建立和连接这个'cyclic_executive.o'文件。编辑makefile以打印出'OBJ'的值并确保它没问题。 –

回答

1

您未链接文件与busy()函数调用。

在命令行试试这个:

gcc main.c cyclic_executive.c 

如果它工作,或者至少不给上busy()功能的错误,那将确认问题。然后尝试

make all 

这应该在执行时打印所有命令。如果您仍然处于黑暗中,请尝试使用

make -d 

这将为您提供大量有关实际制造的诊断信息。

+0

确实没有链接完成。 以下是我所做的: 包括..SUBDIR中的/ common目录 将它从对象中移除 这样就可以在构建main.o的同时创建Makefile的其余部分来完成链接。 我有相同的变量(帧序列0等)的多个声明有新的错误。我认为这很难看,但我只是将它们定义为静态。 我有最后一个警告,因为它们没有在cyclic_executive.c中使用,但我现在还有其他的事情要处理。 谢谢! – 0xeedfade