"undefined reference to setup/loop"

Didn't want to post this due to all the other topics about the same thing, but I couldn't find my problem anywhere else. I'm trying to make a 433mhz transmitter on a Nano Every.
My code is as follows:

// 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;

void setup()
{
  // Initialize ASK Object
  rf_driver.init();
}

void loop()
{
  const char *msg = "Chilling n' grilling";
  rf_driver.send((uint8_t *)msg, strlen(msg));
  rf_driver.waitPacketSent();
  delay(1000);
}

The error message is as follows:

/tmp/ccFjz7s8.ltrans0.ltrans.o: In function `main':

/home/builder/.arduino15/packages/arduino/hardware/megaavr/1.8.7/cores/arduino/main.cpp:43: undefined reference to `setup'

/home/builder/.arduino15/packages/arduino/hardware/megaavr/1.8.7/cores/arduino/main.cpp:46: undefined reference to `loop'

collect2: error: ld returned 1 exit status

Error during build: exit status 1

My sketch name is not "main", and the obligatory setup/loop functions are present.
I can't figure out what's causing the issue.

Welcome to the forum

The Arduino environment uses a hidden main() function, hence the reference to it

Which board have you got selected in the IDE and does the RH_ASK library support the use of the Nano Every ?

Do you have the Radio Head library installed in your IDE (as opposed to locally)?

Hi @garswell ,

if you open the directory

"/home/builder/.arduino15/packages/arduino/hardware/megaavr/1.8.7/cores/arduino/"

you should find the files main.cpp and Arduino.h.

  • setup() and loop() are defined in Arduino.h
  • Both are called in main.cpp

Arduino.h should be included in main.cpp like here

// ...

#include <Arduino.h>

//...

Maybe a re-installation of your hardware libraries might solve the issue ...

Good luck!
ec2021

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.