Trying to create an elf file for two sets of files in different folders.
LIDARBOT.h
-----------
#ifndef LIDARBOT_H_
#define LIDARBOT_H_
#include <avr/io.h>
#include "drivers/motors.h"
#endif
LIDARBOT.C
----------
#include "LIDARBOT.h"
int main(){
pwmtimersetup();
while (1) {
}
}
motors.h
--------
#ifndef MOTORS_H_
#define MOTORS_H_
#include <avr/io.h>
void pwmtimersetup(void);
#endif
motors.c
--------
#include <avr/io.h>
#include "motors.h"
void pwmtimersetup(void){
// Timer pre-scalar for ~490 Hz is 8
TCCR0B &= ~((1<<CS02)||(1<<CS00));
TCCR0B |= (1<<CS01);
// Set Compare Output Mode to Toggle PWM
TCCR0A &= ~(1<<COM0A1);
TCCR0A |= (1<<COM0A0);
// Waveform Generation Mode: WGM02 = 1, WGM01 = 1, WGM00 = 1
TCCR0B |= (1<<WGM02);
TCCR0A |= (1<<WGM01)||(1<<WGM00);
OCR0A = 125;
DDRD |= (1<<DDD4)||(1<<DDD2);
PORTD |= (1<<PORTD4);
PORTD &= (1<<PORTD2);
}
I can make a consolidated object file but not an elf file to load onto my board. Output below:
avr-gcc -g -Os -Wall -Werror -Wextra -mmcu=atmega328p -DF_CPU=1000000UL -Wa,-ahlmns=LIDARBOT.lst -o objects/LIDARBOT.o \
source/LIDARBOT.c \
source/drivers/motors.c \
-I/home/manu/C/Arduino/LIDARBOT/libraries/
avr-gcc -g -Os -Wall -Werror -Wextra -mmcu=atmega328p -DF_CPU=1000000UL -o elf/LIDARBOT.elf objects/LIDARBOT.o
objects/LIDARBOT.o: In function `__vector_22':
(.text+0x7c): multiple definition of `__bad_interrupt'
/usr/lib/gcc/avr/5.4.0/../../../avr/lib/avr5/crtatmega328p.o:(.text+0x0): first defined here
objects/LIDARBOT.o: In function `__vectors':
(.text+0x0): multiple definition of `__vectors'
/usr/lib/gcc/avr/5.4.0/../../../avr/lib/avr5/crtatmega328p.o:(.vectors+0x0): first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:191: elf] Error 1
I am kind of lost. What could be my mistake here? If I see an error like this how do i start to debug?
avr-gcccommand line? In that command line I see multiple source files, only one output file and no-c? This looks like a full compile and link, but saving the resultant elf as an.ofile. But why? What am I missing?