natanaeljr / esp32-MPU-driver

ESP32 full library for all MPU6000 MPU6050 MPU6500 MPU9150 MPU9250 with SPI and I2C support and more.
MIT License
249 stars 67 forks source link

New to ESP-IDF, how to add C++ components? #14

Closed amoghskulkarni closed 5 years ago

amoghskulkarni commented 5 years ago

I'm new to ESP-IDF and have a very basic understanding of CMake and ESP-IDF's build system. I am getting an error while adding the MPU9250 driver component in a Vanilla ESP-IDF hello_world example, and not sure how to proceed. My best guess is that the compiler expects everything to be in C. Here's my error -

Toolchain path: /opt/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc
Toolchain version: crosstool-ng-1.22.0-80-g6c4433a5
Compiler version: 5.2.0
Python requirements from E:/Work/MovTrack/ESP32/esp/esp-idf/requirements.txt are satisfied.

Project is not inside a git repository, will not use 'git describe' to determine PROJECT_VER.
App "mpu9250" version: 1
CC build/main/hello_world_main.o
In file included from E:/Work/MovTrack/ESP32/esp/mpu9250/components/MPUdriver/include/MPU.hpp:47:0,
                 from E:/Work/MovTrack/ESP32/esp/mpu9250/main/hello_world_main.c:15:
E:/Work/MovTrack/ESP32/esp/mpu9250/components/SPIbus/include/SPIbus.hpp:37:1: error: unknown type name 'class'
 class SPI;
 ^
E:/Work/MovTrack/ESP32/esp/mpu9250/components/SPIbus/include/SPIbus.hpp:40:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'hspi'
 extern SPI hspi;
            ^
E:/Work/MovTrack/ESP32/esp/mpu9250/components/SPIbus/include/SPIbus.hpp:41:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'vspi'
 extern SPI vspi;
            ^
E:/Work/MovTrack/ESP32/esp/mpu9250/components/SPIbus/include/SPIbus.hpp:48:1: error: unknown type name 'class'
 class SPI {
 ^
E:/Work/MovTrack/ESP32/esp/mpu9250/components/SPIbus/include/SPIbus.hpp:48:11: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 class SPI {
           ^
E:/Work/MovTrack/ESP32/esp/mpu9250/components/SPIbus/include/SPIbus.hpp:133:3: warning: data definition has no type or storage class
 } SPI_t;
   ^
E:/Work/MovTrack/ESP32/esp/mpu9250/components/SPIbus/include/SPIbus.hpp:133:3: error: type defaults to 'int' in declaration of 'SPI_t' [-Werror=implicit-int]
E:/Work/MovTrack/ESP32/esp/mpu9250/components/SPIbus/include/SPIbus.hpp:137:1: error: unknown type name 'constexpr'
 constexpr SPI_t& getSPI(spi_host_device_t host) {
 ^
.
.
.
.
E:/Work/MovTrack/ESP32/esp/mpu9250/main/hello_world_main.c: At top level:
cc1.exe: warning: unrecognized command line option '-Wno-frame-address'
cc1.exe: some warnings being treated as errors
make[1]: *** [/e/Work/MovTrack/ESP32/esp/esp-idf/make/component_wrapper.mk:290: hello_world_main.o] Error 1
make: *** [E:/Work/MovTrack/ESP32/esp/esp-idf/make/project.mk:579: component-main-build] Error 2

All errors are about C++ keywords like class not being recognized by the compiler. How can I fix this?

amoghskulkarni commented 5 years ago

Never mind, sorted the issue. Started writing an app from scratch and it compiles fine without any error. May be hello_world app which ships with esp-idf examples directory does something funny in it's config..