Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple definitions of std::nothrow on __AVR_ARCH__ #95

Open
zfields opened this issue Mar 5, 2024 · 5 comments
Open

Multiple definitions of std::nothrow on __AVR_ARCH__ #95

zfields opened this issue Mar 5, 2024 · 5 comments

Comments

@zfields
Copy link

zfields commented Mar 5, 2024

I'm not sure if this is the appropriate solution, but to allow an AVR project to compile correctly, I had to wrap the definition of std::nothrow in an #ifdef.

new_handler.cpp

#ifndef __AVR_ARCH__
    const std::nothrow_t std::nothrow = { };
#endif

Here is the compiler error for additional context:

/home/zak/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-gcc -Wall -Wextra -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega2560 -o /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/ArduinoIoTCloud_Basic.ino.elf -Wl,--whole-archive /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/sketch/objs.a /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/libraries/ArduinoSTL/objs.a /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/libraries/ArduinoSTL/abi/objs.a /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/libraries/ArduinoIoTCloud/objs.a /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/libraries/ArduinoIoTCloud/cbor/objs.a /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/libraries/ArduinoIoTCloud/cbor/lib/tinycbor/src/objs.a /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/libraries/ArduinoIoTCloud/property/objs.a /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/libraries/ArduinoIoTCloud/tls/objs.a /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/libraries/ArduinoIoTCloud/tls/bearssl/objs.a /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/libraries/ArduinoIoTCloud/tls/profile/objs.a /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/libraries/ArduinoIoTCloud/tls/utility/objs.a /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/libraries/ArduinoIoTCloud/utility/ota/objs.a /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/libraries/ArduinoIoTCloud/utility/time/objs.a /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/libraries/ArduinoIoTCloud/utility/watchdog/objs.a /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/libraries/Arduino_ConnectionHandler/objs.a /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/libraries/Blues_Wireless_Notecard/objs.a /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/libraries/Blues_Wireless_Notecard/note-c/objs.a /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/libraries/Wire/objs.a /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/libraries/Wire/utility/objs.a /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/libraries/Arduino_DebugUtils/objs.a -Wl,--no-whole-archive /home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build/../../../../../../../tmp/arduino/cores/arduino_avr_mega_97e1bcb735c3b776c955076fa7804c78/core.a -L/home/zak/Development/Arduino/generated_examples/ArduinoIoTCloud_Basic/build -lm
new.cpp.o (symbol from plugin): In function `operator new(unsigned int)':
(.text+0x0): multiple definition of `std::nothrow'
new_handler.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
@thiagovmu
Copy link

Actually, I think that the fix is like below:
const std::nothrow_t nothrow_t {};

@zfields
Copy link
Author

zfields commented Apr 29, 2024

Can you explain that in more detail? It looks like you are defining a new empty function.

I thought the purpose of the file is to define functions in the std:: namespace.

@thiagovmu
Copy link

By reading the code I understood that the intention is to get rid of writing std std all the time for nothrow, therefore, who wrote the code just made the mistake of duplicating the std word (the compiler error you saw).
The way I answered you can see that is just an initialization of nothrow variable where its type is std::nothrow.
Maybe it will be used somewhere else in the project but without the need of writing std::

@AbbottF
Copy link

AbbottF commented May 22, 2024

Thanks for the quick fix. Worked like a charm.

@Ebola-Chan-bot
Copy link

See my fork that should have fixed this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants