我目前正在编写一个简短的测试应用程序。 编译给了我这些错误:目标文件缺失函数符号
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文件,从而给出了正确的声明和原型。
我觉得我做错了,但我的想法很短。 另外,我真的不喜欢我如何声明我的“默认”序列。我知道有一个正确的方法来做到这一点,但我不记得它...有人有一个名字来帮助搜索它吗?
谢谢。
你似乎没有建立和连接这个'cyclic_executive.o'文件。编辑makefile以打印出'OBJ'的值并确保它没问题。 –