Important: Please read the Qt Code of Conduct -

Undefined Reference

  • I am trying to create column-major matrix, but of the constructors gives an undefined reference, but I cannot see the problem. I found similar code in woboq for QMatrix4x4.
    I am using Win11 and mingw. Thanks.

    #include "mymatrix3d.h"
            qreal m11,qreal m12,qreal m13,qreal m14,
            qreal m21,qreal m22,qreal m23,qreal m24,
            qreal m31,qreal m32,qreal m33,qreal m34,
            qreal m41,qreal m42,qreal m43,qreal m44){
    MyMatrix3D::MyMatrix3D(qreal *elements[]){
        for(int row=0; row<4; row++) {
            for(int col=0; col<4; col++) {
                e[row][col]=*elements[row*8 + col];};};

    #ifndef MYMATRIX3D_H
    #define MYMATRIX3D_H
    #include <QtMath>
    #include <QDebug>
    #include <QDebugStateSaver>
    #include "mypoint3d.h"

    class MyMatrix3D
    MyMatrix3D(qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal);
    MyMatrix3D(qreal *elements[]);
    qreal e[4][4];
    qreal row1[4];
    qreal row2[4];
    qreal row3[4];

    #endif // MYMATRIX3D_H

  • Lifetime Qt Champion

    And you really compile mymatrix3d.cpp in your project? I would guess no.

  • Yes. I should have added that it is third constructor that gives the problem.

    I get :
    D:\QtPrograms\build-3DModeling-Desktop_Qt_6_2_0_MinGW_64_bit-Debug..\3DModeling\mainwindow.cpp:14: error: undefined reference to MyMatrix3D::MyMatrix3D(double (*) [4])' debug/mainwindow.o: In functionMainWindow::MainWindow(QWidget*)':
    D:\QtPrograms\build-3DModeling-Desktop_Qt_6_2_0_MinGW_64_bit-Debug/../3DModeling/mainwindow.cpp:14: undefined reference to `MyMatrix3D::MyMatrix3D(double (*) [4])'

  • Lifetime Qt Champion

    How do you call it? Why do you need this ctor at all? Pass a properly aligned std::array so you don't have to make sure it's length is correct.

  • Long story, but the short version is: 1. QMatrix4x4 uses floats and I want qreals because I want to do modeling and not just graphics. 2. Looking ahead when OpenGL will be replaced by renders which will culling will be done on the CPU side. 3. I want to incorporate intrinsics to improve performance.

    What can I do to gather the information to help solve this problem.

    How does it differ from what I found in qmatrix4x4.cpp, namely:

    QMatrix4x4::QMatrix4x4(const float *values)
        for (int row = 0; row < 4; ++row)
            for (int col = 0; col < 4; ++col)
                m[col][row] = values[row * 4 + col];
        flagBits = General;

    Any help will be greatly appreciated, thanks.

  • Lifetime Qt Champion

    The QMatrix ctor takes a pointer to a float, you pass a pointer to a pointer of a float. Both are very problematic because none of them has the chance to check the size of the values.

  • @ofmrew said in Undefined Reference:

    How does it differ from what I found in qmatrix4x4.cpp, namely:

    MyMatrix3D(qreal *elements[])

    is not the same level of indirection as

    QMatrix4x4(const float *values)

    Humour me: if you declared yours as qreal **elements (or qreal *elements if that is what you really intend) that might make the linker error go away?

  • My mistake. If you note the second constructor does what I want: get a two dimensional array of [row ][column] that will allow me to construct a contiguous array of qreals. White the final constructor I was trying to make it less verbose. Some other languages allow something like x[0][:] to return and array with the first row of x[][].

    Also, I will note that I have watching on but I do not get a notification unless I click no the icon, before a number, representing the number of notifications, would appear on the icon.

Log in to reply