Skip to content

Linker errors when using static variables #1595

Closed
@loopj

Description

@loopj

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions