m5stack / M5Core2

M5Core2 Arduino Library
MIT License
267 stars 117 forks source link

Building with Espressif32 (5.2.0) and GNU++17 fails #108

Closed sybrenstuvel closed 2 years ago

sybrenstuvel commented 2 years ago

Describe the bug

Building with PlatformIO option platform = espressif32@5 and build_flags = -std=gnu++17 fails.

The cause seems to be that beta is already a registered top-level symbol:

.pio/libdeps/m5stack-core2/M5Core2/src/utility/quaternionFilters.cpp:35:14: error: 'float beta' conflicts with a previous declaration
 static float beta = sqrt(3.0f / 4.0f) * GyroMeasError;  // Compute beta
              ^~~~
In file included from c:\users\sybren\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\cmath:1892,
                 from c:\users\sybren\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\math.h:36,
                 from C:/Users/Sybren/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal.h:30,
                 from C:/Users/Sybren/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:36,
                 from .pio/libdeps/m5stack-core2/M5Core2/src/utility/quaternionFilters.h:4,
                 from .pio/libdeps/m5stack-core2/M5Core2/src/utility/quaternionFilters.cpp:12:
c:\users\sybren\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\specfun.h:343:5: note: previous declaration 'typename __gnu_cxx::__promote_2<_Tp, _Up>::__type std::beta(_Tpa, _Tpb)'
     beta(_Tpa __a, _Tpb __b)
     ^~~~
.pio/libdeps/m5stack-core2/M5Core2/src/utility/quaternionFilters.cpp: In function 'void MadgwickQuaternionUpdate(float, float, float, float, float, float, float, float, float, float)':
.pio/libdeps/m5stack-core2/M5Core2/src/utility/quaternionFilters.cpp:152:56: error: invalid operands of types '<unresolved overloaded function type>' and 'float' to binary 'operator*'
   qDot1 = 0.5f * (-q2 * gx - q3 * gy - q4 * gz) - beta * s1;
                                                   ~~~~~^~~~
.pio/libdeps/m5stack-core2/M5Core2/src/utility/quaternionFilters.cpp:153:55: error: invalid operands of types '<unresolved overloaded function type>' and 'float' to binary 'operator*'
   qDot2 = 0.5f * (q1 * gx + q3 * gz - q4 * gy) - beta * s2;
                                                  ~~~~~^~~~
.pio/libdeps/m5stack-core2/M5Core2/src/utility/quaternionFilters.cpp:154:55: error: invalid operands of types '<unresolved overloaded function type>' and 'float' to binary 'operator*'
   qDot3 = 0.5f * (q1 * gy - q2 * gz + q4 * gx) - beta * s3;
                                                  ~~~~~^~~~
.pio/libdeps/m5stack-core2/M5Core2/src/utility/quaternionFilters.cpp:155:55: error: invalid operands of types '<unresolved overloaded function type>' and 'float' to binary 'operator*'
   qDot4 = 0.5f * (q1 * gz + q2 * gy - q3 * gx) - beta * s4;

The easiest way to fix this is to rename beta to something more descriptive, like GyroMeasBeta.

To reproduce

With this platformio.ini:

[env:m5core2]
board = m5stack-core2
platform = espressif32@5
framework = arduino
lib_deps =
    m5stack/M5Core2@^0.1.5

build_flags = -std=gnu++17
build_unflags = -std=gnu++11

and this src/main.cpp:

#include <Arduino.h>
#include <M5Core2.h>

void setup() {
  Serial.begin(115200);
  M5.begin(false, false, false, false);
}

void loop() { M5.update(); }

build the project. It should result in the above error.

Expected behavior

I would expect the library to build just fine.

Screenshots

No response

Environment

Additional context

No response

Issue checklist

Tinyu-Zhao commented 2 years ago

fixed #107