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

Undefined reference to __cxa_guard_acquire and __cxa_guard_release #356

Closed
jonblack opened this issue Sep 20, 2016 · 12 comments
Closed

Undefined reference to __cxa_guard_acquire and __cxa_guard_release #356

jonblack opened this issue Sep 20, 2016 · 12 comments

Comments

@jonblack
Copy link

jonblack commented Sep 20, 2016

When I compile the JsonParserExample I get the following error:

build-mega-atmega2560/example.ino.o: In function `ArduinoJson::JsonArray::invalid()':
example.ino:(.text._ZN11ArduinoJson9JsonArray7invalidEv[ArduinoJson::JsonArray::invalid()]+0xc): undefined reference to `__cxa_guard_acquire'
example.ino:(.text._ZN11ArduinoJson9JsonArray7invalidEv[ArduinoJson::JsonArray::invalid()]+0x28): undefined reference to `__cxa_guard_release'
build-mega-atmega2560/example.ino.o: In function `ArduinoJson::JsonObject::invalid()':
example.ino:(.text._ZN11ArduinoJson10JsonObject7invalidEv[ArduinoJson::JsonObject::invalid()]+0xc): undefined reference to `__cxa_guard_acquire'
example.ino:(.text._ZN11ArduinoJson10JsonObject7invalidEv[ArduinoJson::JsonObject::invalid()]+0x28): undefined reference to `__cxa_guard_release'
collect2: error: ld returned 1 exit status
/home/jon/.arduino_mk/Arduino.mk:1416: recipe for target 'build-mega-atmega2560/arduino-example.elf' failed
make: *** [build-mega-atmega2560/arduino-example.elf] Error 1

I remember a similar problem with the Ethernet library a while back and found the issue for it (esp8266/Arduino#574). Perhaps that can help.

@jonblack
Copy link
Author

It turns out this happens because I'm using https://github.com/sudar/Arduino-Makefile to compile the project. When I use the IDE, it works fine.

@bblanchon
Copy link
Owner

bblanchon commented Sep 20, 2016

I would be very interested to know if you find a proper workaround so that I could add it to Compatibility Issues.
It's probably a flag missing in the invocation of the linker.

@jonblack
Copy link
Author

I figured out the problem. I had the following in my Makefile:

CXXFLAGS_STD += -std=gnu++11

Removing this fixed the problem.

@bblanchon
Copy link
Owner

I don't like this because it mean you won't be able to use C++11 features in your code.

Can you try to add this flag instead:

-fno-threadsafe-statics
Do not emit the extra code to use the routines specified in the C++ ABI for thread-safe initialization of local statics. You can use this option to reduce code size slightly in code that doesn't need to be thread-safe.

@jonblack
Copy link
Author

Apparently Arduino defaults to c++14 and I was appending gnuc++11, so it got totally messed up. Should be fine without it.

@satishIoT
Copy link

CXXFLAGS_STD += -std=gnu++11 ; Could you pl give steps where precisely this correction to be made. Im finding very hard to make out.

@bblanchon
Copy link
Owner

bblanchon commented Mar 13, 2017

Hello Satish,

If you use the Arduino IDE, you need to edit the platform.txt of the board you're using:

  • The file is located at %LOCALAPPDATA%\Arduino15\packages\<brand>\hardware\<board>\<version>\platform.txt
  • The line to change is compiler.cpp.flags

I edited the FAQ, so that it'll be easier to find.

Please confirm this solves your problem.

Regards,
Benoit

@satishIoT
Copy link

satishIoT commented Mar 13, 2017 via email

@satishIoT
Copy link

satishIoT commented Mar 13, 2017 via email

@bblanchon
Copy link
Owner

Satish, you should add -fno-threadsafe-statics and keep -std=c++11.

Explanation:

  1. -std=c++11 enables support for the new language features introduced in the C++11 standard, like nullptr
  2. -fno-threadsafe-statics disables the mutex around initialization of local static variables, which is useless when you program is single threaded.

@satishIoT
Copy link

satishIoT commented Mar 13, 2017 via email

@jonblack
Copy link
Author

Just to clarify the cause (for me). I was appending -std=gnu++11 to CXXFLAGS_STD. Because it defaults to -std=gnu++14, I had two standards defined which of course isn't gonna work.

Repository owner locked and limited conversation to collaborators Sep 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants