CybeX
CybeX

Reputation: 2396

qt - undefined reference to `_imp__Z*'

Good day all

Please note: C++ newbie here

I am creating shared libraries among various other c++ features to allow for a complete understanding, however I am at a loss.

Problem:

As the title suggests, a list of errors:

I have no idea what causes them, and googling does not provide much insight either. As suggested here to add the Q_Object macro, I have done so but obviously it is of no use.

Various other SO posts suggest checking the correct header, etc which is correct.

Error:

netm.cpp:3: error: undefined reference to `vtable for netm'
netm.cpp:3: error: undefined reference to `_imp___ZN4miscC1Ev'

netm.cpp:6: error: undefined reference to `vtable for netm'
netm.cpp:6: error: undefined reference to `_imp___ZN4miscC1Ev'
//...

I have several more errors similar to these above, but solving these should assist me in resolving the rest

From all the tutorials, etc I have followed, I have done nothing out of the ordinary.

Note: I am unsure what information is all required, if more is required, I'll gladly share.

//.pro

QT       -= gui
QT       += network

TARGET = netm
TEMPLATE = lib

DEFINES += NETM_LIBRARY

SOURCES += netm.cpp

HEADERS += netm.h\
        netm_global.h

unix {
    target.path = /usr/lib
    INSTALLS += target
}

//netm_global.h - FULL

#ifndef NETM_GLOBAL_H
#define NETM_GLOBAL_H

#include <QtCore/qglobal.h>

#if defined(NETM_LIBRARY)
#  define NETMSHARED_EXPORT Q_DECL_EXPORT
#else
#  define NETMSHARED_EXPORT Q_DECL_IMPORT
#endif

#endif // NETM_GLOBAL_H

//netm.h - FULL

#ifndef NETM_H
#define NETM_H

#include "netm_global.h"
#include "../misc/misc.h"
#include "../gen/gen.h"

#include <QHostInfo>
#include <QTcpSocket>

class NETMSHARED_EXPORT netm
{
    Q_OBJECT

public:
    netm();
    netm(QString hostname);
    bool Send(int portNumber, char* message = NULL);
    ReturnObject read();

    bool isServerOnline(QString IP = QString());
    int getPing(QString IP = QString());
    void getIP();
    void disconnectFromServer();
    ~netm();

private slots:
    void getIP();

private:
    misc m;
    QHostInfo serverInfo;
    QHostAddress serverIP;
    QTcpSocket tcp_con;

};

#endif // NETM_H

//netm.cpp - Partial

#include "netm.h"

netm::netm(){                                    <--- ERROR line
}

netm::netm(QString hostname)                     <--- ERROR line
{
    serverInfo.lookupHost(hostname, 0, SLOT(getIP()));
}

//...

Help (with explanations) would be greatly appreciated!

UPDATE

As suggested, I defined the constructor in misc.cpp, since it was not present.

Recompiling, I read an error mentioning that the netm class needed to inherit from QObject.

Thus adding/changing:

//netm.h - Partial

#include //...
#include <QObject>

class NETMSHARED_EXPORT netm : public QObject
{
    Q_OBJECT

public:
    netm();
    netm(QString hostname);
    //...
};

Errors persist:

netm.cpp:3: error: undefined reference to `_imp___ZN4miscC1Ev'
netm.cpp:3: error: undefined reference to `_imp___ZN4miscD1Ev'
netm.cpp:6: error: undefined reference to `_imp___ZN4miscC1Ev'
netm.cpp:6: error: undefined reference to `_imp___ZN4miscD1Ev'

For completeness sake (misc is also a dynamic library):

//misc.h

#ifndef MISC_H
#define MISC_H

#include "misc_global.h"

#include <QString>
#include <QList>


class MISCSHARED_EXPORT misc
{
public:

    misc();
    ~misc();

    //String Literals
    //Network related
    static QString googleDNS;

    //Command Codes
    static QString CMD_AUTH;
    static QString CMD_REQ;

    //Request Codes
    static QString REQ_USER_INFO;
    static QString REQ_VPN_DATA;
    static QString REQ_VPN_UP;

    //...
};

//misc.cpp

#include "misc.h"

misc::misc(){
    //Network related
    QString googleDNS = QStringLiteral("8.8.8.8");

    //Command Codes
    QString CMD_AUTH = QStringLiteral("AUTH");
    QString CMD_REQ = QStringLiteral("REQ");

    //Request Codes
    QString REQ_USER_INFO = QStringLiteral("USER_INFO");
    QString REQ_VPN_DATA = QStringLiteral("VPN_DATA");
    QString REQ_VPN_UP = QStringLiteral("VPN_UP");
}

misc::~misc(){}

As seen here, the constructor exists,

any other thoughts?

Upvotes: 2

Views: 4491

Answers (1)

nneonneo
nneonneo

Reputation: 179452

Missing calls to _imp___ZN4miscC1Ev, which is misc::misc() according to c++filt, likely means that the class misc is missing a defined default constructor. Check to make sure you're compiling in a definition for misc::misc().

For the vtable error, make sure that you've provided a definition (even if empty or stubbed out) for every function declared in netm (or at minimum all of the virtual functions in netm). The vtable for a class references every virtual function, so all of the virtual functions must be defined or it will not compile.

Upvotes: 3

Related Questions