0

I have a project that I need to use a vector, I have tried to get several libraries to compile with out luck. The one that has gotten the closest is Andy Brown's AVR-STL. I keep getting the error:

C:\Eclipse\eclipse\arduinoPlugin\packages\arduino\hardware\avr\1.6.10\libraries\AVR-STL/pnew.cpp:12:7: error: redefinition of 'void* operator new(size_t, void*)'

I am sure that this is a simple fix, I just have no idea how. If this library is no longer viable then can someone else recommend another one?

Here is the code I am trying to compile

#include "Arduino.h"
#include "iterator"
#include "vector"
#include "pnew.cpp"

std::vector<int> test;

void setup(void) {

    Serial.begin(57600);
}

void loop(void) {

    test.push_back(1);
    Serial.println("Pushed");
}

And the full output:

14:57:27 **** Incremental Build of configuration Release for project MegaTesting ****
"C:\\Eclipse\\eclipse\\arduinoPlugin\\tools\\make\\make" all 
'Building file: ../.ino.cpp'
'Starting C++ compile'
"C:\Eclipse\eclipse\arduinoPlugin\tools\arduino\avr-gcc\4.8.1-arduino5/bin/avr-g++" -c -g -Os -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10606 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR     -I"C:\Eclipse\eclipse\arduinoPlugin\packages\arduino\hardware\avr\1.6.10\cores\arduino" -I"C:\Eclipse\eclipse\arduinoPlugin\packages\arduino\hardware\avr\1.6.10\variants\mega" -I"C:\Eclipse\eclipse\arduinoPlugin\packages\arduino\hardware\avr\1.6.10\libraries\AVR-STL" -I"C:\Eclipse\eclipse\arduinoPlugin\packages\arduino\hardware\avr\1.6.10\libraries\AVR-STL\utility" -MMD -MP -MF".ino.cpp.d" -MT".ino.cpp.o" -D__IN_ECLIPSE__=1 -x c++ "../.ino.cpp"  -o  ".ino.cpp.o"   -Wall
cc1plus.exe: warning: C:\Eclipse\eclipse\arduinoPlugin\packages\arduino\hardware\avr\1.6.10\libraries\AVR-STL\utility: not a directory [enabled by default]
In file included from C:\Eclipse\eclipse\arduinoPlugin\packages\arduino\hardware\avr\1.6.10\libraries\AVR-STL/stl_iterator_base.h:38:0,
                 from C:\Eclipse\eclipse\arduinoPlugin\packages\arduino\hardware\avr\1.6.10\libraries\AVR-STL/iterator:40,
                 from ../.ino.cpp:8:
C:\Eclipse\eclipse\arduinoPlugin\packages\arduino\hardware\avr\1.6.10\libraries\AVR-STL/concept_checks.h: In static member function 'static void _TrivialIterator_concept_specification<_TrivialIterator>::_TrivialIterator_requirement_violation(_TrivialIterator)':
C:\Eclipse\eclipse\arduinoPlugin\packages\arduino\hardware\avr\1.6.10\libraries\AVR-STL/concept_checks.h:572:16: warning: typedef '__T' locally defined but not used [-Wunused-local-typedefs]
     value_type __T;
                ^
C:\Eclipse\eclipse\arduinoPlugin\packages\arduino\hardware\avr\1.6.10\libraries\AVR-STL/concept_checks.h: In static member function 'static void _Allocator_concept_specification<_Alloc>::_Allocator_requirement_violation(_Alloc)':
C:\Eclipse\eclipse\arduinoPlugin\packages\arduino\hardware\avr\1.6.10\libraries\AVR-STL/concept_checks.h:799:39: warning: typedef '_Tp' locally defined but not used [-Wunused-local-typedefs]
   typedef typename _Alloc::value_type _Tp;
                                       ^
In file included from ../MegaTesting.ino:3:0,
                 from ../.ino.cpp:14:
C:\Eclipse\eclipse\arduinoPlugin\packages\arduino\hardware\avr\1.6.10\libraries\AVR-STL/pnew.cpp: In function 'void* operator new(size_t, void*)':
C:\Eclipse\eclipse\arduinoPlugin\packages\arduino\hardware\avr\1.6.10\libraries\AVR-STL/pnew.cpp:12:7: error: redefinition of 'void* operator new(size_t, void*)'
 void* operator new(size_t size_,void *ptr_){
       ^
In file included from ../.ino.cpp:10:0:
C:\Eclipse\eclipse\arduinoPlugin\packages\arduino\hardware\avr\1.6.10\libraries\AVR-STL/pnew.cpp:12:7: error: 'void* operator new(size_t, void*)' previously defined here
 void* operator new(size_t size_,void *ptr_){
       ^
subdir.mk:24: recipe for target '.ino.cpp.o' failed
make: *** [.ino.cpp.o] Error 1

14:57:28 Build Finished (took 600ms)
1
  • I've got the "Andy Browns method" of standard library working. But I believe I didn't have the same error as you. A redefinition would mean that something has already been defined, I think you can choose to not include it at some point, since it's already defined.
    – aaa
    Commented Jun 2, 2016 at 12:29

1 Answer 1

1

It looks like new is redefined. I see that you include cpp file, that contains implementation - this is rather unfortunate design, but that's how it is done.

Anyway, it seems that this file is already being compiled elsewhere. Have you tried to remove this include? What happens if you remove it?

Apart from that problem, you must be aware that dynamic memory management in such small system yelds risk of memory fragmentation that eventually leads to failed allocations.

3
  • That's the thing, I have tried excluding the pnew.cpp and believe it or not I get a Undefined message, even if I include Arduino.h before any of this library. Commented May 12, 2016 at 23:25
  • Are you able to allocate anything using new? It should be available since 1.0.5 or something. Try int *i = new int[5];. Commented May 12, 2016 at 23:39
  • Thats the weird thing about this, I do have the 'new' functionality at runtime thats why I am thinking that it has to do with either an include or header because new is available without using this lib Commented May 13, 2016 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.