Important: Please read the Qt Code of Conduct -

LNK2001 can't resolve external symbol

  • Hi, I am trying to make my QOpenGLWindow class a singleton so I can access from anywhere but I have an error that says :

    glwindow.obj:-1: error: LNK2001: símbolo externo "private: static class glwindow * glwindow::instance" (?instance@glwindow@@0PEAV1@EA) sin resolver

    The attribute that is throwing me that error is:

    static glwindow *instance;

    I have re-run QMake and also I have rebuilt all the proyect so I don't know what to do know.
    I have another class that is working as a singleton and I have no problem with it.

    This is my glwindow .h:

    class glwindow : public QOpenGLWidget, protected QOpenGLFunctions_4_1_Core
        static glwindow *getInstance();
        bool eventFilter(QObject *obj, QEvent *event) override;
        void window_refresh();
        void initializeGL() override;
        void resizeGL(int w, int h) override;
        void paintGL() override;
         ~glwindow() override;
        glwindow(QWidget *parent = nullptr);
        static glwindow *instance;
        void printContextInformation();


  • Lifetime Qt Champion

    @JesusM said in LNK2001 can't resolve external symbol:

    static glwindow *instance;

    Where do you have the definition for this? It's missing in glwindow.cpp I would guess.

  • @Christian-Ehrlicher

    Oh, I know what you mean. I had it initialized in the constructor but, as it is an static attribute I had to initialized it outside

    glwindow::glwindow(QWidget *parent): QOpenGLWidget (parent)
        instance = nullptr;

    So now I put it outside any function and It work's. My bad

    glwindow * glwindow::instance = nullptr;

    Thanks .

Log in to reply