Hi everyone,
tl;dr
When running the code below, the macro for abs
defined in wiring.h
interferes with the use of std::abs()
.
I stumbled across an issue which leaves me baffled I must admit. I was working for the last 2 years on a project with stepper motors that make use of std
functions and so far everything was fine. However, yesterday I decided to come up with a complete clean platformio environment and deleted the .platformio folder (stupid me). After re-installing the platformio-extension in VSCode I got plenty of compiler errors. It turned out that the #define abs
in wiring.h
is in conflict with std::abs()
as it tries to replace abs
with the macro, which does not make sense with regards to the std
namespace. What I really don’t understand is, how is this now an issue and it has not been an issue before.
Unfortunately, I have no specifics about the platformio environment before the cleaning. The current (!) platformio dependencies and verbose build are shown below.
I understand that I could change all std::abs()
to abs
as a workaround but I really want to understand and solve the problem.
What am I missing here and why is there all of a sudden this issue?
I am very thankfull for any advice what could be going on.
Cheers,
Daniel
src/main.cpp
#include <Arduino.h>
void setup() {
// abs(-6); // macro from wiring.h
// std::abs(-6); // should work fine, but triggers compiler errors due to macro
// std::cos(0.1); // for testing that std functions work in general
}
void loop() {
}
platformio.ini
[env:teensy36]
platform = teensy
board = teensy36
framework = arduino
Dependencies
Resolving teensy36 dependencies...
Platform teensy @ 4.18.0 (required: teensy)
├── framework-arduinoteensy @ 1.158.0 (required: platformio/framework-arduinoteensy @ ~1.158.0)
└── toolchain-gccarmnoneeabi-teensy @ 1.110301.0 (required: platformio/toolchain-gccarmnoneeabi-teensy @ ~1.110301.0)
Verbose build
Processing teensy36 (platform: teensy; board: teensy36; framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/teensy/teensy36.html
PLATFORM: Teensy (4.18.0) > Teensy 3.6
HARDWARE: MK66FX1M0 180MHz, 256KB RAM, 1MB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES:
- framework-arduinoteensy @ 1.158.0 (1.58)
- toolchain-gccarmnoneeabi-teensy @ 1.110301.0 (11.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 92 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
arm-none-eabi-g++ -o .pio\build\teensy36\src\main.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m4 -nostdlib -mfloat-abi=hard -mfpu=fpv4-sp-d16 -O2 -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60106 -D__MK66FX1M0__ -DARDUINO_TEENSY36 -DUSB_SERIAL -DARDUINO=10805 -DTEENSYDUINO=158 -DCORE_TEENSY -DF_CPU=180000000L -DLAYOUT_US_ENGLISH -Iinclude -Isrc -IC:\Users\Daniel\.platformio\packages\framework-arduinoteensy\cores\teensy3 src\main.cpp