"Undefined reference to '__cxa_guard_acquire'" error message

Follow

Comments

4 comments

  • Avatar
    Pintu Kumar

    Hello, To resolve this undefined references (__cxa_guard_acquire ) , add a library flag "-lstdc++" in your Makefile. It should work. It worked for me.

    T&R,

    Pintu

  • Avatar
    Chad B

    I'm trying to implement the Singleton pattern and am getting this same error. Can anyone please elaborate on the steps required to solve this issue? Thanks.

  • Avatar
    Javier Box

    I get the same thing on a singleton pattern. Why? 

    static Graphics_c& GetInstance(){static Graphics_c instance; return instance;};

  • Avatar
    Rod Gilchrist

    This implementation of a singleton pattern will cause the issue (and can be fixed as Paul describes above):

    rb_controller& rb_controller::singleton()

    {

        static rb_controller singleton_instance;

        return singleton_instance;

    }

     

    This implementation doesn't cause the issue in the first place:

     

    class rb_controller {

    private:

        static rb_controller *singleton_instance;

    public:

    };

     

    rb_controller *rb_controller::singleton_instance = NULL;

     

    rb_controller& rb_controller::singleton()

    {

      if (singleton_instance == NULL) {

        singleton_instance = new rb_controller();

      }

      return *singleton_instance;

    }

    }

Please sign in to leave a comment.