c++ 为什么延迟指令会导致编译器错误?

yc0p9oo0  于 2023-05-24  发布在  其他
关注(0)|答案(1)|浏览(183)

当我在代码中添加delay(timer)时,编译器抛出一个错误,timer是在代码开头定义的常量整数。
当我注解掉延迟线时,编译器成功完成。
倒数第四行

// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependant SPI Library 
#include <SPI.h> 

// Create Amplitude Shift Keying Object
RH_ASK rf_driver;

const int BLUE = 3;     // the number of the pushbutton pin
const int GREEN = 4;      // the number of the LED pin
const int RED = 5;      // the number of the LED pin
const int thisPin = 4;
const int timer = 100;

// the setup function runs once when you press reset or power the board
void setup() {
  // Initialize ASK Object
  rf_driver.init();
  Serial.begin(9600);
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
    int mesg = 0;
    // Set buffer to size of expected message
    uint8_t buf[8];
    uint8_t buflen = sizeof(buf);
    if (rf_driver.recv(buf, &buflen)) {
      // Message received with valid checksum
      Serial.print("Message Received: ");
      Serial.println((char*)buf);     
      mesg = 1;
    }
    if (mesg == 1) {
      mesg = 0;
      digitalWrite(thisPin, HIGH);
      //delay(timer);
      digitalWrite(thisPin, LOW);
    }
}

下面是错误消息:

C:\Users\Swee-Chuan Khoo\Documents\Arduino\libraries\RadioHead\RH_ASK.cpp: In member function 'setModeIdle.constprop':

C:\Users\Swee-Chuan Khoo\Documents\Arduino\libraries\RadioHead\RH_ASK.cpp:421:1: internal compiler error: Segmentation fault

 }

 ^

Please submit a full bug report,

with preprocessed source if appropriate.

See <http://gcc.gnu.org/bugs.html> for instructions.

lto-wrapper.exe: fatal error: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avr-gcc returned 1 exit status

compilation terminated.

c:/program files/windowsapps/arduinollc.arduinoide_1.8.21.0_x86__mdqgnx93n4wtt/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino Nano.
kwvwclae

kwvwclae1#

根据Juraj的建议,将AVR核心降级至1.6.21。现在一切正常。
现在我可以继续这个项目了。
谢谢大家的帮助,datafiddler,Juraj和M.R.

相关问题