2

In my class I am trying to create a new instance of my webserver object:

.h

class Stub : public QObject
{
    Q_OBJECT

public:
    Stub(QObject *parent = 0);
    ~Stub();    

private:
    WebSocketServer *m_webSocketServer;

.cpp

Stub::Stub(QObject *parent)
    : QObject(parent)
{
    //Start Websocket-Server
    m_webSocketServer = new WebSocketServer(8000, true,this);   
}

My server constructor looks like:

explicit WebSocketServer(quint16 port, bool v = true, QObject *parent = Q_NULLPTR);

but it throws errors like this:

Error 7 error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall WebSocketServer::~WebSocketServer(void)" (__imp_??1WebSocketServer@@UAE@XZ) referenced in function "public: virtual void * __thiscall WebSocketServer::`scalar deleting destructor'(unsigned int)" (??

Error 10 error LNK2001: unresolved external symbol "public: virtual void * __thiscall WebSocketServer::qt_metacast(char const *)" (?qt_metacast@WebSocketServer@@UAEPAXPBD@Z)

Error 8 error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall WebSocketServer::metaObject(void)const " (?metaObject@WebSocketServer@@UBEPBUQMetaObject@@XZ)

Error 9 error LNK2001: unresolved external symbol "public: virtual int __thiscall WebSocketServer::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@WebSocketServer@@UAEHW4Call@QMetaObject@@HPAPAX@Z)

my webserver is working, just when creating instance of that it crashes. I tried adding libraries, included .h files, all names match

Dušan Tichý
  • 498
  • 1
  • 7
  • 21
  • 1
    It does not crash. It gets linker errors. Seems like you declared the destructor but did not implement it – Hayt Oct 06 '16 at 11:57
  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Hayt Oct 06 '16 at 11:58
  • That's a very peculiar definition of "working". I don't think my manager would buy it. – molbdnilo Oct 06 '16 at 11:59
  • @molbdnilo just wanted to tell you, I think its not important to show code of that. its actualy a library that I imported – Dušan Tichý Oct 06 '16 at 12:03
  • @DušanTichý I suspect that you forgot to link with that library. – molbdnilo Oct 06 '16 at 12:07
  • @molbdnilo I included header files and lib files for linker, probably not the problem, when I comment that creating of new instance, everything works – Dušan Tichý Oct 06 '16 at 12:11
  • @Hayt destructor is implemented. – Dušan Tichý Oct 06 '16 at 12:19
  • where is you class `WebSocketServer`implemented? unresolved external symbols mean you have declared something which is not defined. – Hayt Oct 06 '16 at 12:23
  • @Hayt sorry if I have stupid questions, what u mean where? I have all the file at disk... i just include headers and added lib file in project properties. thanks for trying to help. – Dušan Tichý Oct 06 '16 at 12:26
  • Is `WebSocketServer` your class? Like do you have a cpp file for it? And does the cpp file gets compiled? – Hayt Oct 06 '16 at 12:28
  • I have .cpp, I dont know if its compiled, when i try to compile just header file with its declaration, it is compiled. – Dušan Tichý Oct 06 '16 at 12:33

1 Answers1

1

I got it:

What I had to do:

  1. Checked again if I added libraries and I noticed I put it to wrong place

Project -> Properties -> Configuration Properties -> Linker -> General -> Additional dependencies

but It was supposed to be inside this:

Project -> Properties -> Configuration Properties -> Linker -> Input-> Additional dependencies

  1. Even when I added it correctly, I got error with missing .dll file, so what I've done is I put missing .dll copy into output directory (Project -> Properties -> Configuration Properties -> General-> Output Directory)

Now it works as I intened.

Thanks all for effort.

Dušan Tichý
  • 498
  • 1
  • 7
  • 21