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

Linker errors when using static variables #1595

Closed
loopj opened this issue Feb 6, 2016 · 1 comment
Closed

Linker errors when using static variables #1595

loopj opened this issue Feb 6, 2016 · 1 comment

Comments

@loopj
Copy link

loopj commented Feb 6, 2016

When writing code like this:

class BMP085 {
public:
    static BMP085& getInstance() {
        static BMP085 instance;
        return instance;
    }
};

I'm seeing linker errors complaining about missing abi functions __cxa_guard_acquire and __cxa_guard_release:

Sensors.cpp:(.text._ZN6BMP08511getInstanceEv[BMP085::getInstance()]+0x29): undefined reference to `__cxa_guard_acquire'
Sensors.cpp:(.text._ZN6BMP08511getInstanceEv[BMP085::getInstance()]+0x38): undefined reference to `__cxa_guard_release'

Should we add definitions for these functions to abi.h/abi.c to allow use of statics in these situtions? This is what arduino's avr core does:

__extension__ typedef int __guard __attribute__((mode (__DI__)));
extern "C" {
    int __cxa_guard_acquire(__guard *g) {return !*(char *)(g);};
    void __cxa_guard_release(__guard *g) {*(char *)g = 1;};
}

Or am I doing something fundamentally wrong here? Happy to provide a PR.

@loopj
Copy link
Author

loopj commented Feb 6, 2016

Looks like there is already a PR open for this at #1586! Closing this issue

@loopj loopj closed this as completed Feb 6, 2016
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

1 participant