【发布时间】:2020-10-27 16:12:13
【问题描述】:
在我的代码中,我只使用 LiquidCrystal 库和 Servo 库。当我尝试编译代码时出现以下错误
Servo/Servo.cpp.o: In function `Servo::attached()':
/usr/share/arduino/libraries/Servo/Servo.cpp:336: multiple definition of `__vector_42'
robot_v2.cpp.o:/usr/share/arduino/robot_v2.ino:662: first defined here
/usr/lib/gcc/avr/5.4.0/../../../avr/bin/ld: Disabling relaxation: it will not work with multiple definitions
Servo/Servo.cpp.o: In function `Servo::attached()':
/usr/share/arduino/libraries/Servo/Servo.cpp:336: multiple definition of `__vector_47'
robot_v2.cpp.o:/usr/share/arduino/robot_v2.ino:662: first defined here
collect2: error: ld returned 1 exit status
除了上面提到的库之外,我使用了一个 16 位定时器,如下所示。
DDRC |= B01010101;
......
cli();
TCCR4A = 0;
TCCR4B = 0;
TCCR5A = 0;
TCCR5B = 0;
OCR4A = l_target;
OCR5A = l_target;
TCCR4B = _BV(WGM42) | _BV(CS41);
TCCR5B = _BV(WGM52) | _BV(CS51);
TIMSK4 |= (1 << OCIE4A);
TIMSK5 |= (1 << OCIE5A);
sei();
让我知道我做错了什么以及如何解决这个问题?除了 arduino 的标准伺服库之外,还有其他库吗?我正在使用 Arduino Mega 板。
这里是 ISR。
ISR(TIMER4_COMPA_vect)
{
if (OCR4A != l_target) {
OCR4A = l_target;
}
PORTC ^= B00000001;
}
ISR(TIMER5_COMPA_vect)
{
if (OCR5A != r_target) {
OCR5A = r_target;
}
PORTC ^= B00010000;
}
【问题讨论】:
-
我认为 __vector_47 指的是 ISR,你能检查一下你的代码没有定义 ISR 两次吗?在编译器指向的地方搜索。 :)
-
@dunajski 我已经添加了代码。请检查我是否做错了什么。
-
伺服库是否使用定时器 4 和 5?如果有,解决办法是什么?