I’m using the sample sketch Custom_Sensitivity provided with the Arduino_MKRIoTCarrier library. When building, I’m getting collect2: error: ld returned 1 exit status
I’m struggling to pinpoint where the error is coming from or how to fix it. In the Arduino IDE this sample sketch compiles with no errors. I’m fairly new to PlatformIO so any suggestions or leads would be greatly appreciated.
My build output:
CONFIGURATION: https://docs.platformio.org/page/boards/atmelsam/mkrwifi1010.html
PLATFORM: Atmel SAM (6.2.0) > Arduino MKR WiFi 1010
HARDWARE: SAMD21G18A 48MHz, 32KB RAM, 256KB Flash
DEBUG: Current (atmel-ice) External (atmel-ice, blackmagic, jlink)
PACKAGES:
- framework-arduino-samd 1.8.11
- framework-cmsis 1.40500.0 (4.5.0)
- framework-cmsis-atmel 1.2.2
- toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 25 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Arduino_MKRIoTCarrier> 1.0.1
| |-- <Wire> 1.0
| |-- <Arduino_BQ24195> 0.9.1
| | |-- <Wire> 1.0
| |-- <Arduino_APDS9960> 1.0.3
| | |-- <Wire> 1.0
| |-- <Arduino_LPS22HB> 1.0.1
| | |-- <Wire> 1.0
| |-- <Arduino_LSM6DS3> 1.0.0
| | |-- <SPI> 1.0
| | |-- <Wire> 1.0
| |-- <SPI> 1.0
| |-- <Arduino_HTS221> 1.0.0
| | |-- <Wire> 1.0
| |-- <Arduino_MCHPTouch> 1.1.0
| |-- <SD> 0.0.0-alpha+sha.041f788250
| | |-- <SPI> 1.0
| |-- <Adafruit GFX Library> 1.10.10
| | |-- <SPI> 1.0
| | |-- <Adafruit BusIO> 1.8.1
| | | |-- <Wire> 1.0
| | | |-- <SPI> 1.0
| | |-- <Wire> 1.0
| |-- <Adafruit ST7735 and ST7789 Library> 1.7.3
| | |-- <Adafruit GFX Library> 1.10.10
| | | |-- <SPI> 1.0
| | | |-- <Adafruit BusIO> 1.8.1
| | | | |-- <Wire> 1.0
| | | | |-- <SPI> 1.0
| | | |-- <Wire> 1.0
| | |-- <SPI> 1.0
| |-- <Adafruit DotStar> 1.1.4
| | |-- <SPI> 1.0
|-- <Adafruit BusIO> 1.8.1
| |-- <Wire> 1.0
| |-- <SPI> 1.0
Building in release mode
Compiling .pio/build/mkrwifi1010/src/main.cpp.o
In file included from .pio/libdeps/mkrwifi1010/Arduino_MKRIoTCarrier/src/Arduino_MKRIoTCarrier.h:37:0,
from src/main.cpp:3:
.pio/libdeps/mkrwifi1010/Arduino_MKRIoTCarrier/src/Arduino_MKRIoTCarrier_Qtouch.h:27:13: warning: '_available' defined but not used [-Wunused-variable]
static bool _available = false;
^~~~~~~~~~
Linking .pio/build/mkrwifi1010/firmware.elf
.pio/build/mkrwifi1010/lib339/libArduino_MCHPTouch.a(touch.c.o): In function `touch_sensors_init':
touch.c:(.text.touch_sensors_init+0x12): undefined reference to `touch_selfcap_sensors_init_with_rs_table'
touch.c:(.text.touch_sensors_init+0x38): undefined reference to `touch_selfcap_sensor_config'
touch.c:(.text.touch_sensors_init+0x56): undefined reference to `touch_selfcap_sensor_config'
touch.c:(.text.touch_sensors_init+0x74): undefined reference to `touch_selfcap_sensor_config'
touch.c:(.text.touch_sensors_init+0x92): undefined reference to `touch_selfcap_sensor_config'
touch.c:(.text.touch_sensors_init+0xb0): undefined reference to `touch_selfcap_sensor_config'
touch.c:(.text.touch_sensors_init+0xbc): undefined reference to `touch_selfcap_sensors_calibrate'
.pio/build/mkrwifi1010/lib339/libArduino_MCHPTouch.a(touch.c.o): In function `touch_sensors_measure':
touch.c:(.text.touch_sensors_measure+0x16): undefined reference to `touch_selfcap_sensors_measure'
collect2: error: ld returned 1 exit status
*** [.pio/build/mkrwifi1010/firmware.elf] Error 1
========================== [FAILED] Took 5.62 seconds =======================
From the build output I got the impression the error was coming from undefined reference to touch_selfcap_sensors_X
, however, I opened that library and using VS Code’s Go to Definition I can consistently find the references to those functions. I also tried renaming the file to touch.cpp (as suggested in other discussions), but still got the same error.
My main.cpp:
#include <Arduino.h>
// Not in original example, added to satisfy dependency error
#include <Adafruit_I2CDevice.h>
#include "Arduino_MKRIoTCarrier.h"
MKRIoTCarrier carrier;
unsigned int threshold = 98;
void setup() {
Serial.begin(9600);
while (!Serial);
carrier.begin();
carrier.Buttons.updateConfig(threshold);
}
void loop() {
carrier.Buttons.update();
if (carrier.Buttons.getTouch(TOUCH0)) {
Serial.println("touching 0");
}
if (carrier.Buttons.getTouch(TOUCH1)) {
Serial.println("touching 1");
}
}
And my platform.ini:
[env:mkrwifi1010]
platform = atmelsam
board = mkrwifi1010
framework = arduino
lib_deps = arduino-libraries/Arduino_MKRIoTCarrier@^1.0.1
If it helps at all, the “top-level” library Arduino_MKRIoTCarrier
can be found in this GitHub Repo and the Arduino_MCHPTouch
library which contains the file touch.c
is from this GitHub repo.