ArduinoSTL icon indicating copy to clipboard operation
ArduinoSTL copied to clipboard

multiple definition of `std::nothrow'

Open jfjlaros opened this issue 1 year ago • 13 comments

When compiling the following sketch,

#include <ArduinoSTL.h>

void setup() {}
void loop() {}

this error is raised:

arduino-cli compile --fqbn arduino:avr:pro --warnings all --output-dir build \
    --build-property compiler.cpp.extra_flags="-pedantic"
new.cpp.o (symbol from plugin): In function `operator new(unsigned int)':
(.text+0x0): multiple definition of `std::nothrow'
/tmp/arduino-sketch-DAE3E2C59CB46B47AC6BC234B0EB1886/libraries/ArduinoSTL/new_handler.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2: error: ld returned 1 exit status

Commenting out line 22 of src/new_handler.cpp seems to fix the issue, but this perhaps introduces other problems.

My set up:

  • arduino-cli Version: 0.25.1 Commit: 436f0bb9 Date: 2022-07-25T15:01:55Z
  • ArduinoSTL version 1.3.3
  • arduino:avr core version 1.8.5

This issue can be reproduced in the Wokwi simulator.

jfjlaros avatar Aug 06 '22 10:08 jfjlaros

Same here!

Also #79 presents the same issue.

fabianoriccardi avatar Aug 21 '22 15:08 fabianoriccardi

downgrading to arduino:avr core version 1.8.3 fixed the issue.

POberauer avatar Oct 11 '22 19:10 POberauer

or as @jfjlaros states, remore / comment line 22 in ../ArduinoSTL/src/new_handler.cpp: const std::nothrow_t std::nothrow = { }; since for arduino core v1.8.5, std::nothrow, is already defined in its ../core/arduino/new.cpp file.

POberauer avatar Oct 11 '22 20:10 POberauer

Was getting the same exact error. If I open the library file ArduinoSTL/src/new_handler.cpp and comment out line 22: // const std::nothrow_t std::nothrow = { }; It will allow my program to compile.

rw3iss avatar Dec 05 '22 09:12 rw3iss

I'm getting the same error. The workaround posted by @rw3iss works.

quinn-n avatar Dec 29 '22 20:12 quinn-n

same error here, fix by @rw3iss worked

crashback-exe avatar Jan 02 '23 01:01 crashback-exe

same error, @rw3iss 's workaround worked.

mabsch avatar Feb 15 '23 06:02 mabsch

you are right ,thanks

zhangyonggang316 avatar Mar 20 '23 09:03 zhangyonggang316

Même erreur ;) Merci @rw3iss

odisseano avatar Nov 14 '23 15:11 odisseano

hi all,

is there going to be an official fix to this issue? i.e. a fix that does not require downgrading other libraries nor commenting out lines of code.

please advise.

thanks in advance, rey malahay

reymalahay avatar Nov 29 '23 02:11 reymalahay

Was getting the same exact error. If I open the library file ArduinoSTL/src/new_handler.cpp and comment out line 22: // const std::nothrow_t std::nothrow = { }; It will allow my program to compile.

If this is not needed shall we create a PR to delete it, or guarded in some conditional MACRO?

#ifdef xxx
...
#endif

mw66 avatar Jan 20 '24 19:01 mw66

I have created PR #94 to implement the suggestion made in the first post of this issue.

jfjlaros avatar Jan 20 '24 21:01 jfjlaros