开发者

C++ LNK2019 ( between project classes )

开发者 https://www.devze.com 2023-01-16 14:33 出处:网络
I have an very strange error: when I want to use the SocialServer::Client class from my SocialServer::Server class, the linker threw me two LNK2019 errors :

I have an very strange error: when I want to use the SocialServer::Client class from my SocialServer::Server class, the linker threw me two LNK2019 errors :

Error 1 error LNK2019: unresolved external symbol "public: void __thiscall SocialServer::Client::Handle(void)" (?Handle@Client@SocialServer@@QAEXXZ) referenced in function "private: static unsigned int __stdcall SocialServer::Server::listenThread(void *)" (?listenThread@Server@SocialServer@@CGIPAX@Z) C:\Users\benjamin\Documents\Visual Studio 2010\Projects\FCX Social Server\SocialServer Core\Server.obj SocialServer Core

Error 2 error LNK2019: unresolved external symbol "public: __thiscall 开发者_运维知识库SocialServer::Client::Client(unsigned int)" (??0Client@SocialServer@@QAE@I@Z) referenced in function "private: static unsigned int __stdcall SocialServer::Server::listenThread(void *)" (?listenThread@Server@SocialServer@@CGIPAX@Z) C:\Users\benjamin\Documents\Visual Studio 2010\Projects\FCX Social Server\SocialServer Core\Server.obj SocialServer Core

However , these 2 missing function are correctly implemented :

Client.h

#pragma once

#include "dll.h"

namespace SocialServer
{
    class __social_class Client
    {
    public:
        Client(SOCKET sock);
        ~Client();

        void Handle();

    private:
        static unsigned __stdcall clientThread(void* value);

        SOCKET _socket;
        uintptr_t _thread;
        unsigned int _thread_id;
    };
}

Client.cpp

#pragma once

#include "Client.h"

namespace SocialServer
{
 Client::Client(SOCKET socket)
 {
  this->_socket = socket;
 }

 Client::~Client()
 {
 }

 void Client::Handle()
 {
  std::cout << " New client " << std::endl;
  this->_thread = _beginthreadex(NULL, 0, Client::clientThread, &this->_socket, CREATE_SUSPENDED, &this->_thread_id);
  ResumeThread((HANDLE)this->_thread);
 }

 unsigned __stdcall Client::clientThread(void* value)
 { 
  // Some code to execute here ...
 }
}

Where does the problem comes from ?


i've found the solution. In a function that's used by _beginthreadex() (with unsigned __stdcall) , always add a return at the end.

0

精彩评论

暂无评论...
验证码 换一张
取 消