6

I added a class IcecastServer to my QT-project, added the header-file to the pro file and added some code. Everytime I compile it the following errors occur:

release/icecastserver.o:icecastserver.cpp:(.text+0x39): undefined reference to _imp___ZN10QTcpServerC1EP7QObject' release/icecastserver.o:icecastserver.cpp:(.text+0x50): undefined reference toimpZN12QHostAddressC1ENS_14SpecialAddressE' release/icecastserver.o:icecastserver.cpp:(.text+0x68): undefined reference to _imp___ZN10QTcpServer6listenERK12QHostAddresst' release/icecastserver.o:icecastserver.cpp:(.text+0x73): undefined reference to_imp_ZN12QHostAddressD1Ev' release/icecastserver.o:icecastserver.cpp:(.text+0x9d): undefined reference to _imp___ZNK10QTcpServer11errorStringEv' release/icecastserver.o:icecastserver.cpp:(.text+0x3d4): undefined reference toimpZN12QHostAddressD1Ev' release/icecastserver.o:icecastserver.cpp:(.text+0x4bd): undefined reference to _imp___ZN10QTcpServerC1EP7QObject' release/icecastserver.o:icecastserver.cpp:(.text+0x4d4): undefined reference to_imp_ZN12QHostAddressC1ENS_14SpecialAddressE' release/icecastserver.o:icecastserver.cpp:(.text+0x4ec): undefined reference to _imp___ZN10QTcpServer6listenERK12QHostAddresst' release/icecastserver.o:icecastserver.cpp:(.text+0x4f7): undefined reference toimpZN12QHostAddressD1Ev' release/icecastserver.o:icecastserver.cpp:(.text+0x521): undefined reference to _imp___ZNK10QTcpServer11errorStringEv' release/icecastserver.o:icecastserver.cpp:(.text+0x858): undefined reference to_imp_ZN12QHostAddressD1Ev'

What am I doing wrong?

This is the header-file:

#ifndef ICECASTSERVER_H
#define ICECASTSERVER_H

#include <QObject>

QT_BEGIN_NAMESPACE
class QTcpServer;
QT_END_NAMESPACE

class IcecastServer : public QObject
{
    Q_OBJECT
public:
    explicit IcecastServer(QObject *parent = 0);

signals:

public slots:

private:
    QTcpServer *tcpServer;
};

#endif // ICECASTSERVER_H

This is the source-file:

#include "icecastserver.h"
#include "QDebug"
#include <QtNetwork/QTcpServer>
#include <QtGui>

IcecastServer::IcecastServer(QObject *parent) :
    QObject(parent)
{

    tcpServer = new QTcpServer(this);
    //tcpServer->listen(QHostAddress::Any,8000);

    if (!tcpServer->listen()){
        QMessageBox::critical(NULL, tr("Fortune Server"), tr("Unable to start the server: %1.").arg(tcpServer->errorString()));

         return;
    }

}

2 Answers 2

7

First you need to #include <QHostAddress> somewhere assuming that commented out line is what caused the problem.

You may also to check some project settings to see if you have all the correct inputs.

Edit: More detail

QtNetwork requires QT network lib inputs. Assuming once again that you are using QtCreator as not much info was provided then this means in your .pro file you need to have a line like so:

QT += network

Then make sure you include the right headers for the objects you are using before using them. If you still get undefined references, linking errors, etc try a QMake and rebuild. If it still persists you probably have errors in your code in addition to QT usage errors and should validate that your methods and objects being used were properly declared.

Final Edit: Glad that worked ...

When you create a new project in QTCreator there is a step in the wizard where you can check off the various QT libraries you want to include which will add these .pro lines and inputs for you. This is QT version of inputting additional lib files and by default they will be statically linked I believe. If you want to dynamically link with shared objects or dll then there is some extra configuration steps.

Sign up to request clarification or add additional context in comments.

2 Comments

I added that include but as you said, its commented out, so that didn't fix the problem. Which inputs are you talking about?
for QT += network the reference can be found at doc.qt.io/qt-4.8/qmake-variable-reference.html#qt
1

Are you running the moc tool over your header file? Are you subsequently compiling the output from the moc tool?

2 Comments

I'm using the Qt Creator. What I did is executing qmake and then running the program.
@Hedge QMake runs the moc (meta object compiler) tool so that would be a yes assuming you have QtCreator setup to build out of date sources before running the executable which is the default behavior. You only need to do this when changing or adding Q_OBJECT stuff usually.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.