PlatformIO Community

Linker error with Adafruit Feather M0


#1

Hello,

I’m running into a linker error with a very basic project using Adafruit Feather M0. I’m running PIO 4.0.0a4. Here’s my code:

In src/main.cpp:

void setup() { }
void loop() { }

Then when I build project:

Processing adafruit_feather_m0 (platform: atmelsam; board: adafruit_feather_m0; framework: arduino)

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelsam/adafruit_feather_m0.html
PLATFORM: Atmel SAM > Adafruit Feather M0
HARDWARE: SAMD21G18A 48MHz 32KB RAM (256KB Flash)
DEBUG: CURRENT(atmel-ice) EXTERNAL(atmel-ice, blackmagic, jlink)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 7 compatible libraries
Scanning dependencies...
No dependencies
Compiling .pioenvs\adafruit_feather_m0\src\main.cpp.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduinoVariant\variant.cpp.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\IPAddress.cpp.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\Print.cpp.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\Reset.cpp.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\SERCOM.cpp.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\Stream.cpp.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\Tone.cpp.o
Archiving .pioenvs\adafruit_feather_m0\libFrameworkArduinoVariant.a
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\USB\CDC.cpp.o
Indexing .pioenvs\adafruit_feather_m0\libFrameworkArduinoVariant.a
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\USB\PluggableUSB.cpp.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\USB\SAMD21_USBDevice.cpp.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\USB\USBCore.cpp.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\USB\samd21_host.c.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\Uart.cpp.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\WInterrupts.c.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\WMath.cpp.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\WString.cpp.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\abi.cpp.o
C:\Users\vince\.platformio\packages\framework-arduinosam\cores\adafruit\USB\USBCore.cpp: In member function 'void USBDeviceClass::initEP(uint32_t, uint32_t)':
C:\Users\vince\.platformio\packages\framework-arduinosam\cores\adafruit\USB\USBCore.cpp:505:53: warning: deleting object of polymorphic class type 'DoubleBufferedEPOutHandler' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
delete (DoubleBufferedEPOutHandler*)epHandlers[ep];
^
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\avr\dtostrf.c.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\cortex_handlers.c.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\delay.c.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\hooks.c.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\itoa.c.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\main.cpp.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\math_helper.c.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\new.cpp.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\pulse.c.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\pulse_asm.S.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\startup.c.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\wiring.c.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\wiring_analog.c.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\wiring_digital.c.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\wiring_private.c.o
Compiling .pioenvs\adafruit_feather_m0\FrameworkArduino\wiring_shift.c.o
C:\Users\vince\.platformio\packages\framework-arduinosam\cores\adafruit\wiring_analog.c:35:12: warning: '_dacResolution' defined but not used [-Wunused-variable]
static int _dacResolution = 10;
^
Archiving .pioenvs\adafruit_feather_m0\libFrameworkArduino.a
Indexing .pioenvs\adafruit_feather_m0\libFrameworkArduino.a
Linking .pioenvs\adafruit_feather_m0\firmware.elf
.pioenvs\adafruit_feather_m0\libFrameworkArduino.a(main.cpp.o): In function `main':
main.cpp:(.text.startup.main+0x22): undefined reference to `setup'
main.cpp:(.text.startup.main+0x26): undefined reference to `loop'
collect2.exe: error: ld returned 1 exit status
*** [.pioenvs\adafruit_feather_m0\firmware.elf] Error 1

The linker seems to be ignoring my main.cpp.o … I’ve tried upgrading PIO, cleaning the project, start a new project etc. I’m running it without issue on Uno board, but not on Feather M0.

Thanks


#2

Where are the function parenthesis? void setup() {} and void loop() {} not void setup {} and void loop {}. Also maybe #include <Arduino.h>


#3

I forgot them while typing but they aren’t missing in the actual code. Including Arduino.h seems to have solved the issue. Thanks !


#4

Heh. Actually what #include <Arduino.h> causes is that setup and loop are declared as extern "C" so they don’t get the C++ name mangling! The startup assembler files reference the functions by the unmangled name. This one also works :slight_smile:

extern "C" void setup()
{
}

extern "C" void loop()
{
}