mike-matera / ArduinoSTL

An STL and iostream implementation based on uClibc++ that supports my CS-11M class.
GNU General Public License v3.0
325 stars 80 forks source link

Failed compilation of code using ArduinoSTL.h and array on Arduino Uno AVR Boards 1.8.3 #66

Closed salwaElkaddaoui closed 2 years ago

salwaElkaddaoui commented 3 years ago

I have written arduino C++ code in which I used std::array quite a lot. Of course I made sure to #include<ArduinoSTL.h> and #include<array>. The compiler raises multiple compilation errors (see below) without pointing to any line of the code:

/home/salwa/Arduino/libraries/ArduinoSTL/src/del_opvs.cpp:25:53: error: 'std::size_t' has not been declared _UCXXEXPORT void operator delete[](void * ptr, std::size_t) throw(){ ^~~~~~ /home/salwa/Arduino/libraries/ArduinoSTL/src/del_ops.cpp:25:50: error: 'std::size_t' has not been declared _UCXXEXPORT void operator delete(void* ptr, std::size_t) throw(){ ^~~~~~ /home/salwa/Arduino/libraries/ArduinoSTL/src/del_opnt.cpp:25:56: error: 'nothrow_t' in namespace 'std' does not name a type _UCXXEXPORT void operator delete(void* ptr, const std::nothrow_t& ) throw() { ^~~~~~~~~ /home/salwa/Arduino/libraries/ArduinoSTL/src/new_opnt.cpp:25:37: error: declaration of 'operator new' as non-function _UCXXEXPORT void* operator new(std::size_t numBytes, const std::nothrow_t& ) throw(){ ^~~~~~ /home/salwa/Arduino/libraries/ArduinoSTL/src/new_opnt.cpp:25:37: error: 'size_t' is not a member of 'std' /home/salwa/Arduino/libraries/ArduinoSTL/src/new_opnt.cpp:25:37: note: suggested alternative: /home/salwa/Arduino/libraries/ArduinoSTL/src/new_handler.cpp:22:12: error: 'nothrow_t' in namespace 'std' does not name a type const std::nothrow_t std::nothrow = { }; ^~~~~~~~~ /home/salwa/Arduino/libraries/ArduinoSTL/src/new_handler.cpp:25:6: error: 'new_handler' in namespace 'std' does not name a type std::new_handler __new_handler; ^~~~~~~~~~~ /home/salwa/Arduino/libraries/ArduinoSTL/src/new_handler.cpp:27:1: error: '_UCXXEXPORT' does not name a type

A similar issue was opened here https://github.com/mike-matera/ArduinoSTL/issues/56, it was suggested to use #include"ArduinoSTL.h" instead of #include<ArduinoSTL.h>, I did that but it didn't work. I also tried downgrading the AVR boards manager from 1.8.3 to 1.8.2 and to 1.8.1 but that didn't seem to solve the problem.

Any suggestions?

dasfdlinux commented 3 years ago

Have you tried using Arduino 1.8.12? I'm also facing issues related to Arduino 1.8.13 and ArduinoSTL, and had to downgrade to 1.8.12 (hopefully temporarily).

salwaElkaddaoui commented 3 years ago

@dasfdlinux No I didn't, I rewrote the code using c arrays, but thanks for the suggestion.

BCsabaEngine commented 3 years ago

Waiting for... and thanks!

blackpancake commented 3 years ago

The same issue here. image

Arduino IDE version: 1.8.13 ArduinoSTL version: 1.1.0 Platform: Windows 10

chrisflesher commented 3 years ago

Same issue for me.

Arduino IDE version: 1.8.13 ArduinoSTL version: 1.1.0 Platform: Ubuntu 20.04

kleurbleur commented 3 years ago

Some problem here.

Arduino IDE version: 1.8.15, 1.8.13, 1.8.12, 1.8.11 ArduinoSTL version: 1.1.0, 1.0.2 Platform: MacOS 10.15.7

================= I can use the lib again with Arduino 1.8.15 in combination with Arduino AVR Boards 1.8.2 from the boards manager.

ZhongKang97 commented 3 years ago

Same issue.

Arduino IDE version: 1.8.16 ArduinoSTL version: 1.1.0 Arduino AVR Boards 1.8.3 Platform: Windows10 + VS2019 image

mahyar1284 commented 3 years ago

same issue on windows 11

tonk777 commented 3 years ago

The cause of the problem is two fold

  1. The newest Arduino IDE have introduced their own header file "new" - this is different and incompatible to the ArduinoSTL header file "new" - for one the IDE provided version does not define std::nothrow_t and it does not inherit std::size_t defined in cstddef

  2. The ArduinoSTL code base uses #include < new > - which means that it may not use the local version of "new" specific to ArduinoSTL . The IDE sets the include file search path which forces ArduinoSTL to pick up the wrong version

The solution is that throughout the ArduinoSTL code base, the header files it uses that are part of ArduinoSTL should use:

include "new"

as this ensures that the included file is found path relative to the including file. It avoids the problems of #include < new > which uses the defined IDE include path and can (and does) pick up the wrong version.

The quick fix to the problem is to change #include < new > to #include "new" in the following ArduinoSTL files

del_op.cpp del_opnt.cpp del_opv.cpp del_opvnt.cpp new_handler.cpp new_op.cpp new_opnt.cpp new_opv.cpp new_opvnt.cpp

The proper fix is a wholesale conversion of #include < xxx > to #include "xxx" for including all local ArduinoSTL header files in the ArduinoSTL xxx.cpp source files to ensure that if the Arduino IDE adds in its own versions of any of the ArduinoSTL header files, that this issue does not occur again

mike-matera commented 2 years ago

It's fixed now! Thank you.

BCsabaEngine commented 2 years ago

We will try it. Thx!!!