Firmware.elf error on multiple environments

Hi, I’m trying to have several smaller test codes and I will eventually run them one by one. So I started with the first one I want to run and I’m getting this when a build and upload:

C:\Users\cphip\AppData\Local\Temp\ccsrf9mk.ltrans0.ltrans.o: In function main': <artificial>:(.text.startup+0x13e): undefined reference to setup’
:(.text.startup+0x146): undefined reference to `loop’
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\lasersandmotors\firmware.elf] Error 1

Here is my .ini file:

[env]
platform = atmelmegaavr
board = nano_every
framework = arduino
;Single firmware arduino nano every
[env:lasersandmotors]
build_src_filter = +<*> -<lnm.cpp> ;Build and upload the lazer and motor test firmware

Here is the lnm.cpp file:

#include <Arduino.h>
#define M1 2
#define M2 3
#define M3 4
#define M4 5
#define L1 6
#define L2 7
#define L3 8
#define L4 9
void setup()
{
Serial.begin(9600);
//Motor pin init
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
pinMode(M3, OUTPUT);
pinMode(M4, OUTPUT);
digitalWrite(M1, LOW);
digitalWrite(M2, LOW);
digitalWrite(M3, LOW);
digitalWrite(M4, LOW);
//Laser Pin init
pinMode(L1, OUTPUT);
pinMode(L2, OUTPUT);
pinMode(L3, OUTPUT);
pinMode(L4, OUTPUT);
digitalWrite(L1, LOW);
digitalWrite(L2, LOW);
digitalWrite(L3, LOW);
digitalWrite(L4, LOW);
}
void loop()
{
digitalWrite(L1, HIGH);
digitalWrite(L2, HIGH);
digitalWrite(L3, HIGH);
digitalWrite(L4, HIGH);
digitalWrite(M1, HIGH);
digitalWrite(M2, HIGH);
digitalWrite(M3, HIGH);
digitalWrite(M4, HIGH);
delay(1000);
}

This line says: “Include all files, but exclude the lnm.cpp

Since lnm.cpp is the only file to build there is nothing to build.
There is no setup() and no loop() which results in the undefined reference error.

You want it the other way around:

[env:lasersandmotors]
build_src_filter = 
  -<*>; exclude everything
  +<lnm.cpp> ; build lnm.cpp

See also

1 Like