问题描述
我正在尝试在 Contiki 中执行一个简单的程序,以在两个数字之间生成一个随机数,然后将其闪存到 Zolertia 模块上。
我的代码是:
#include <stdio.h>
#include <stdlib.h>
#include "contiki.h"
#include <sys/node-id.h>
PROCESS(test_randnum,"Random Number");
AUTOSTART_PROCESSES(&test_randnum);
static struct etimer et;
PROCESS_THREAD(test_randnum,ev,data)
{
PROCESS_BEGIN();
int16_t r;
//random_init(node_id);
//unsigned short r = random_arnd();
while(1){
etimer_set(&et,CLOCK_SECOND);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
r = rand() % (40 - 20) + 20;
printf("Number: %d\n",r);
etimer_reset(&et);
}
PROCESS_END();
}
user@iot-workshop:~/Desktop/Projeto$ make
using saved target 'zoul'
CC test_randnum.c
CC ../../contiki//cpu/cc2538/./ieee-addr.c
CC ../../contiki//cpu/cc2538/cc2538.lds
CC ../../contiki//cpu/cc2538/./startup-gcc.c
CC test_randnum.c
LD test_randnum.elf
test_randnum.co:(.data.test_randnum+0x0): multiple deFinition of `test_randnum'
obj_zoul/test_randnum.o:(.data.test_randnum+0x0): first defined here
collect2: error: ld returned 1 exit status
../../contiki//cpu/cc2538/Makefile.cc2538:100: recipe for target 'test_randnum.elf' Failed
make: *** [test_randnum.elf] Error 1
rm obj_zoul/startup-gcc.o test_randnum.co
这是我的 Makefile:
DEFInes+=PROJECT_CONF_H=\"project-conf.h\"
CONTIKI_PROJECT = test_randnum
CONTIKI_TARGET_SOURCEFILES += test_randnum.c
all: $(CONTIKI_PROJECT)
CONTIKI = ../../contiki/
include $(CONTIKI)/Makefile.include
已经尝试寻找解决方案但没有结果,这是我第一次出现此错误。 有大佬知道怎么解决吗?
谢谢!
解决方法
这是链接器“ld”错误。我们可以看到 make 命令的输出包含 'CC test_randnum.c' 两次,这是不寻常的。很难说不查看您的 makefile 来建议一些修复。