C++ set-up question
Posted: Thu Nov 09, 2017 11:12 am
Hi all,
I'm just starting to dig into ESP-IDF and I need to port some C++ classes over from my old Arduino platform, but I've hit what I suspect is a really stupid problem on my part.
I've been though the details in the following post https://esp32.com/viewtopic.php?t=362 and I've also got a copy of Neil Kolban's ESP32 book which I'm using as a guide for C++ integration.
Here's how I've got to this point.
Created a new proeject based on the details in Neils book by git'ing the esp-idf-template and ran make menuconfig and make - which results in a clean compile.
Added the triangle cpp and h files from bengchet's zip into the main directory
Added '' to the component.mk in the same dir.
Compile works fine.
Replaced main.c with bengchet's fixed code from the forum post and it blows chunks.
______________________________________________________
CC build/main/main.o
In file included from C:/msys32/home/Phil/esp/myapp/main/main.c:8:0:
C:/msys32/home/Phil/esp/myapp/main/triangle.h:11:1: error: unknown type name 'class'
class Triangle{
^
C:/msys32/home/Phil/esp/myapp/main/triangle.h:11:15: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
class Triangle{
^
C:/msys32/home/Phil/esp/myapp/main/main.c:10:1: error: unknown type name 'Triangle'
Triangle polygon(3, 4, 5); //<--- example class
^
C:/msys32/home/Phil/esp/myapp/main/main.c:10:18: error: expected declaration specifiers or '...' before numeric constant
Triangle polygon(3, 4, 5); //<--- example class
^
C:/msys32/home/Phil/esp/myapp/main/main.c:10:21: error: expected declaration specifiers or '...' before numeric constant
Triangle polygon(3, 4, 5); //<--- example class
^
C:/msys32/home/Phil/esp/myapp/main/main.c:10:24: error: expected declaration specifiers or '...' before numeric constant
Triangle polygon(3, 4, 5); //<--- example class
^
C:/msys32/home/Phil/esp/myapp/main/main.c:17:8: error: expected identifier or '(' before string constant
extern "C" int app_main(void)
^
make[1]: *** [/home/Phil/esp/esp-idf/make/component_wrapper.mk:243: main.o] Error 1
make: *** [C:/msys32/home/Phil/esp/esp-idf/make/project.mk:435: component-main-build] Error 2
______________________________________________________
I've also had the same issues when I use Neil's MyClass C++ example from his book (fixing the myStaticFunc issue) with a fresh esp-idf-templated app, it seems to fail with the class definition the same as with the triangle class.
Halp!
I'm just starting to dig into ESP-IDF and I need to port some C++ classes over from my old Arduino platform, but I've hit what I suspect is a really stupid problem on my part.
I've been though the details in the following post https://esp32.com/viewtopic.php?t=362 and I've also got a copy of Neil Kolban's ESP32 book which I'm using as a guide for C++ integration.
Here's how I've got to this point.
Created a new proeject based on the details in Neils book by git'ing the esp-idf-template and ran make menuconfig and make - which results in a clean compile.
Added the triangle cpp and h files from bengchet's zip into the main directory
Added '
Code: Select all
COMPONENT_ADD_LDFLAGS=-lstdc++ -l$(COMPONENT_NAME)
Compile works fine.
Replaced main.c with bengchet's fixed code from the forum post and it blows chunks.
______________________________________________________
CC build/main/main.o
In file included from C:/msys32/home/Phil/esp/myapp/main/main.c:8:0:
C:/msys32/home/Phil/esp/myapp/main/triangle.h:11:1: error: unknown type name 'class'
class Triangle{
^
C:/msys32/home/Phil/esp/myapp/main/triangle.h:11:15: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
class Triangle{
^
C:/msys32/home/Phil/esp/myapp/main/main.c:10:1: error: unknown type name 'Triangle'
Triangle polygon(3, 4, 5); //<--- example class
^
C:/msys32/home/Phil/esp/myapp/main/main.c:10:18: error: expected declaration specifiers or '...' before numeric constant
Triangle polygon(3, 4, 5); //<--- example class
^
C:/msys32/home/Phil/esp/myapp/main/main.c:10:21: error: expected declaration specifiers or '...' before numeric constant
Triangle polygon(3, 4, 5); //<--- example class
^
C:/msys32/home/Phil/esp/myapp/main/main.c:10:24: error: expected declaration specifiers or '...' before numeric constant
Triangle polygon(3, 4, 5); //<--- example class
^
C:/msys32/home/Phil/esp/myapp/main/main.c:17:8: error: expected identifier or '(' before string constant
extern "C" int app_main(void)
^
make[1]: *** [/home/Phil/esp/esp-idf/make/component_wrapper.mk:243: main.o] Error 1
make: *** [C:/msys32/home/Phil/esp/esp-idf/make/project.mk:435: component-main-build] Error 2
______________________________________________________
I've also had the same issues when I use Neil's MyClass C++ example from his book (fixing the myStaticFunc issue) with a fresh esp-idf-templated app, it seems to fail with the class definition the same as with the triangle class.
Halp!