Reputation: 83
I'm trying to do a simple program in Contiki to generate a random number between two numbers and then flash it on a Zolertia module.
My code is:
#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();
}
However when trying to compile the file I get the following "multiple definition" error:
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
Here's my 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
Already tried to look for a solution but got no results and this is the first time this error is appearing to me. Does anyone know how to solve this out?
Thank you!
Upvotes: 1
Views: 719
Reputation: 41
This is linker 'ld' error. We can see that the output of make command contains 'CC test_randnum.c' two times which is unusual. It is hard to say without looking into your makefile to suggest some fix.
Upvotes: 1