Search code examples
c++constructorlinker-errorsunresolved-external

LNK2019 unresolved external symbol in constructor despite having definition in cpp


I am sure this question has been asked before, but I've searched the SO as much I could and still couldn't find the exact reason for the error. Thus posting a new one.

I am using a C++ library (txmpp) in my project. The library is added properly, but I am getting a lot of unresolved external symbol issue, mostly in constructor of the classes I am trying to use. For example, in the following class -

xmppthread.h

#ifndef _HELLO_XMPPTHREAD_H_
#define _HELLO_XMPPTHREAD_H_

#include "../../thread.h"
#include "../../xmppclientsettings.h"
#include "xmpppump.h"

namespace txmpp {

class XmppThread: public txmpp::Thread, XmppPumpNotify, txmpp::MessageHandler {
  public:
    XmppThread();
    ~XmppThread();

    XmppClient* client() { return pump_->client(); }

    void ProcessMessages(int cms);
    void Login(const txmpp::XmppClientSettings & xcs);
    void Disconnect();

  private:
    XmppPump* pump_;

    void OnStateChange(txmpp::XmppEngine::State state);
    void OnMessage(txmpp::Message* pmsg);
};

}  // namespace txmpp

#endif  // _HELLO_XMPPTHREAD_H_

xmppthread.cc

#include "xmppthread.h"

#include <assert.h>
#include "../../prexmppauthimpl.h"
#include "../../xmppasyncsocketimpl.h"
#include "../../xmppclientsettings.h"

namespace txmpp {
namespace {

const uint32 MSG_LOGIN = 1;
const uint32 MSG_DISCONNECT = 2;

struct LoginData : public MessageData {
  LoginData(const XmppClientSettings& s) : xcs(s) {}
  virtual ~LoginData() {}
  XmppClientSettings xcs;
};

} // namespace

XmppThread::XmppThread() {
  pump_ = new XmppPump(this);
}

XmppThread::~XmppThread() {
  delete pump_;
}

void XmppThread::ProcessMessages(int cms) {
  Thread::ProcessMessages(cms);
}

void XmppThread::Login(const XmppClientSettings& xcs) {
  Post(this, MSG_LOGIN, new LoginData(xcs));
}

void XmppThread::Disconnect() {
  Post(this, MSG_DISCONNECT);
}

void XmppThread::OnStateChange(XmppEngine::State state) {
}

void XmppThread::OnMessage(Message* pmsg) {
  switch (pmsg->message_id) {
    case MSG_LOGIN: {
      assert(pmsg->pdata);
      LoginData* data = reinterpret_cast<LoginData*>(pmsg->pdata);
      pump_->DoLogin(data->xcs, new XmppAsyncSocketImpl(true),
                     new PreXmppAuthImpl());
      delete data;
      }
      break;
    case MSG_DISCONNECT:
      pump_->DoDisconnect();
      break;
    default:
      assert(false);
  }
}

}  // namespace hello

I am getting the following error -

1>XMPPController.obj : error LNK2019: unresolved external symbol "public: __thiscall txmpp::XmppThread::XmppThread(void)" (??0XmppThread@txmpp@@QAE@XZ) referenced in function "public: void __thiscall XMPPController::Init(void)" (?Init@XMPPController@@QAEXXZ)
1>XMPPController.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall txmpp::XmppThread::~XmppThread(void)" (??1XmppThread@txmpp@@UAE@XZ) referenced in function "public: void __thiscall XMPPController::Init(void)" (?Init@XMPPController@@QAEXXZ)

I usually see this kinda linker error only when the definition of the function(constructor/destructor in this case) is not provided. However as you can see the definition is included. This error generates only when I do this in my project -

xmpp::XmppThread thread;

As soon as I remove the declaration statement, the linking error goes. The issue is none of this code is written by me and have been taken from the txmpp library. This particular class is from libjingle library of Google, so I am sure I am making some really silly mistake here.

I don't want this question to be a "Here's my code, solve it" one. Instead I want to know what could be the circumstances in which unresolved external symbol error can occur despite having declaration?(The code is there to provide proof that the implementation is there)

Any suggestion?

Update
Here's the exact output I am getting after turning off supress startup banner option -

 1>LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/FORCE' specification
    1>AirPlaySystem.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:LBR' specification
    1>LIBCMTD.lib(sscanf.obj) : warning LNK4006: _vsscanf already defined in s3e_d.lib(iwcrt_win32.obj); second definition ignored
    1>LIBCMTD.lib(strtoq.obj) : warning LNK4006: _strtof already defined in s3e_d.lib(iwcrt_common.obj); second definition ignored
    1>     Creating library Debug_BarnC_vc12_x86\BarnC.lib and object Debug_BarnC_vc12_x86\BarnC.exp
    1>XMPPController.obj : error LNK2019: unresolved external symbol "public: __thiscall txmpp::XmppThread::XmppThread(void)" (??0XmppThread@txmpp@@QAE@XZ) referenced in function "public: void __thiscall XMPPController::Init(void)" (?Init@XMPPController@@QAEXXZ)
    1>XMPPController.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall txmpp::XmppThread::~XmppThread(void)" (??1XmppThread@txmpp@@UAE@XZ) referenced in function "public: void __thiscall XMPPController::Init(void)" (?Init@XMPPController@@QAEXXZ)
    1>Debug_BarnC_vc12_x86\BarnC.s86 : fatal error LNK1120: 2 unresolved externals
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Update 2: This is the detailed linker output after adding verbose linker command line option -

1>  Microsoft (R) Incremental Linker Version 12.00.31101.0
1>  Copyright (C) Microsoft Corporation.  All rights reserved.
1>  
1>  "/OUT:Debug_BarnC_vc12_x86\BarnC.s86" /INCREMENTAL /LIBPATH:d:/marmalade/7.4/modules/third_party/sqlite/lib/x86 /LIBPATH:d:/marmalade/7.4/modules/iwutil/lib/x86 /LIBPATH:d:/marmalade/7.4/modules/third_party/libjpeg/lib/x86 /LIBPATH:d:/marmalade/7.4/modules/third_party/zlib/lib/x86 /LIBPATH:d:/marmalade/7.4/modules/third_party/libpng/lib/x86 /LIBPATH:d:/marmalade/7.4/modules/iw2d/lib/x86 /LIBPATH:d:/marmalade/7.4/modules/iwgx/atitools /LIBPATH:d:/marmalade/7.4/modules/iwgx/lib/x86 /LIBPATH:d:/marmalade/7.4/modules/iwgl/lib/x86 /LIBPATH:d:/marmalade/7.4/modules/iwgeom/lib/x86 /LIBPATH:d:/marmalade/7.4/modules/iwresmanager/lib/x86 /LIBPATH:d:/marmalade/7.4/modules/iwgxfont/lib/x86 /LIBPATH:d:/marmalade/7.4/modules/third_party/tiniconv/lib/x86 /LIBPATH:d:/marmalade/7.4/modules/iwui/lib/x86 /LIBPATH:d:/marmalade/7.4/modules/iwhttp/lib/x86 /LIBPATH:d:/marmalade/7.4/extensions/s3etxmpp/lib/x86 /LIBPATH:d:/marmalade/7.4/s3e/lib/x86 vc6_compat.lib sqlite_d.lib iwutil_d.lib jpeg_d.lib z_d.lib png_d.lib iw2d_d.lib ATI_Compress_MT_VC7.lib iwgx_d.lib iwgl_d.lib iwgeom_d.lib iwresmanager_d.lib iwgxfont_ttf_d.lib tiniconv_d.lib iwui_d.lib iwhttp_d.lib s3eTxmpp_d.lib s3e_cpp_d.lib s3e_d.lib s3e_api_iwgl.lib /NODEFAULTLIB:libcmt /MANIFEST:NO /DEBUG "/PDB:Debug_BarnC_vc12_x86\BarnC.pdb" /SUBSYSTEM:WINDOWS /OPT:NOREF /OPT:NOICF /TLBID:1 "/ENTRY:DllEntryPoint" /DYNAMICBASE /NXCOMPAT "/IMPLIB:Debug_BarnC_vc12_x86\BarnC.lib" /MACHINE:X86 /include:_IwMain /include:_raise /include:_DllEntryPoint@12 /force:multiple /VERBOSE:LIB /DLL Debug_BarnC_vc12_x86\AirPlaySystem.obj 
1>  Debug_BarnC_vc12_x86\CTextField.obj 
1>  Debug_BarnC_vc12_x86\Chat.obj 
1>  Debug_BarnC_vc12_x86\ChatController.obj 
1>  Debug_BarnC_vc12_x86\ChatGroup.obj 
1>  Debug_BarnC_vc12_x86\ChatMenu.obj 
1>  Debug_BarnC_vc12_x86\Contact.obj 
1>  Debug_BarnC_vc12_x86\ContactController.obj 
1>  Debug_BarnC_vc12_x86\HttpManager.obj 
1>  Debug_BarnC_vc12_x86\LoginMenu.obj 
1>  Debug_BarnC_vc12_x86\Main.obj 
1>  Debug_BarnC_vc12_x86\MainMenu.obj 
1>  Debug_BarnC_vc12_x86\MenuBase.obj 
1>  Debug_BarnC_vc12_x86\MenuController.obj 
1>  Debug_BarnC_vc12_x86\PVRTexTool_interface.obj 
1>  Debug_BarnC_vc12_x86\SimpleTouch.obj 
1>  Debug_BarnC_vc12_x86\UnivApp.obj 
1>  Debug_BarnC_vc12_x86\XMPPController.obj 
1>  Debug_BarnC_vc12_x86\md5c.obj 
1>LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/FORCE' specification
1>AirPlaySystem.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:LBR' specification
1>  
1>  Searching libraries
1>      Searching d:/marmalade/7.4/modules/third_party/sqlite/lib/x86\sqlite_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwutil/lib/x86\iwutil_d.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/libjpeg/lib/x86\jpeg_d.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/zlib/lib/x86\z_d.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/libpng/lib/x86\png_d.lib:
1>      Searching d:/marmalade/7.4/modules/iw2d/lib/x86\iw2d_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwgx/atitools\ATI_Compress_MT_VC7.lib:
1>      Searching d:/marmalade/7.4/modules/iwgx/lib/x86\iwgx_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwgl/lib/x86\iwgl_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwgeom/lib/x86\iwgeom_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwresmanager/lib/x86\iwresmanager_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwgxfont/lib/x86\iwgxfont_ttf_d.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/tiniconv/lib/x86\tiniconv_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwui/lib/x86\iwui_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwhttp/lib/x86\iwhttp_d.lib:
1>      Searching d:/marmalade/7.4/extensions/s3etxmpp/lib/x86\s3eTxmpp_d.lib:
1>      Searching d:/marmalade/7.4/s3e/lib/x86\s3e_cpp_d.lib:
1>      Searching d:/marmalade/7.4/s3e/lib/x86\s3e_d.lib:
1>      Searching d:/marmalade/7.4/s3e/lib/x86\s3e_api_iwgl.lib:
1>      Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\OLDNAMES.lib:
1>      Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\LIBCMTD.lib:
1>LIBCMTD.lib(sscanf.obj) : warning LNK4006: _vsscanf already defined in s3e_d.lib(iwcrt_win32.obj); second definition ignored
1>LIBCMTD.lib(strtoq.obj) : warning LNK4006: _strtof already defined in s3e_d.lib(iwcrt_common.obj); second definition ignored
1>      Searching C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x86\uuid.lib:
1>      Searching C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x86\kernel32.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/sqlite/lib/x86\sqlite_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwutil/lib/x86\iwutil_d.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/libjpeg/lib/x86\jpeg_d.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/zlib/lib/x86\z_d.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/libpng/lib/x86\png_d.lib:
1>      Searching d:/marmalade/7.4/modules/iw2d/lib/x86\iw2d_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwgx/atitools\ATI_Compress_MT_VC7.lib:
1>      Searching d:/marmalade/7.4/modules/iwgx/lib/x86\iwgx_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwgl/lib/x86\iwgl_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwgeom/lib/x86\iwgeom_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwresmanager/lib/x86\iwresmanager_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwgxfont/lib/x86\iwgxfont_ttf_d.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/tiniconv/lib/x86\tiniconv_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwui/lib/x86\iwui_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwhttp/lib/x86\iwhttp_d.lib:
1>      Searching d:/marmalade/7.4/extensions/s3etxmpp/lib/x86\s3eTxmpp_d.lib:
1>      Searching d:/marmalade/7.4/s3e/lib/x86\s3e_cpp_d.lib:
1>      Searching d:/marmalade/7.4/s3e/lib/x86\s3e_d.lib:
1>      Searching d:/marmalade/7.4/s3e/lib/x86\s3e_api_iwgl.lib:
1>      Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\OLDNAMES.lib:
1>      Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\LIBCMTD.lib:
1>      Searching C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x86\uuid.lib:
1>      Searching C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x86\kernel32.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/sqlite/lib/x86\sqlite_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwutil/lib/x86\iwutil_d.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/libjpeg/lib/x86\jpeg_d.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/zlib/lib/x86\z_d.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/libpng/lib/x86\png_d.lib:
1>      Searching d:/marmalade/7.4/modules/iw2d/lib/x86\iw2d_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwgx/atitools\ATI_Compress_MT_VC7.lib:
1>      Searching d:/marmalade/7.4/modules/iwgx/lib/x86\iwgx_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwgl/lib/x86\iwgl_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwgeom/lib/x86\iwgeom_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwresmanager/lib/x86\iwresmanager_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwgxfont/lib/x86\iwgxfont_ttf_d.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/tiniconv/lib/x86\tiniconv_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwui/lib/x86\iwui_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwhttp/lib/x86\iwhttp_d.lib:
1>      Searching d:/marmalade/7.4/extensions/s3etxmpp/lib/x86\s3eTxmpp_d.lib:
1>      Searching d:/marmalade/7.4/s3e/lib/x86\s3e_cpp_d.lib:
1>  
1>  Finished searching libraries
1>     Creating library Debug_BarnC_vc12_x86\BarnC.lib and object Debug_BarnC_vc12_x86\BarnC.exp
1>  
1>  Searching libraries
1>      Searching d:/marmalade/7.4/modules/third_party/sqlite/lib/x86\sqlite_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwutil/lib/x86\iwutil_d.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/libjpeg/lib/x86\jpeg_d.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/zlib/lib/x86\z_d.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/libpng/lib/x86\png_d.lib:
1>      Searching d:/marmalade/7.4/modules/iw2d/lib/x86\iw2d_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwgx/atitools\ATI_Compress_MT_VC7.lib:
1>      Searching d:/marmalade/7.4/modules/iwgx/lib/x86\iwgx_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwgl/lib/x86\iwgl_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwgeom/lib/x86\iwgeom_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwresmanager/lib/x86\iwresmanager_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwgxfont/lib/x86\iwgxfont_ttf_d.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/tiniconv/lib/x86\tiniconv_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwui/lib/x86\iwui_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwhttp/lib/x86\iwhttp_d.lib:
1>      Searching d:/marmalade/7.4/extensions/s3etxmpp/lib/x86\s3eTxmpp_d.lib:
1>      Searching d:/marmalade/7.4/s3e/lib/x86\s3e_cpp_d.lib:
1>      Searching d:/marmalade/7.4/s3e/lib/x86\s3e_d.lib:
1>      Searching d:/marmalade/7.4/s3e/lib/x86\s3e_api_iwgl.lib:
1>      Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\OLDNAMES.lib:
1>      Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\LIBCMTD.lib:
1>      Searching C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x86\uuid.lib:
1>      Searching C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x86\kernel32.lib:
1>  
1>  Finished searching libraries
1>  
1>  Searching libraries
1>      Searching d:/marmalade/7.4/modules/third_party/sqlite/lib/x86\sqlite_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwutil/lib/x86\iwutil_d.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/libjpeg/lib/x86\jpeg_d.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/zlib/lib/x86\z_d.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/libpng/lib/x86\png_d.lib:
1>      Searching d:/marmalade/7.4/modules/iw2d/lib/x86\iw2d_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwgx/atitools\ATI_Compress_MT_VC7.lib:
1>      Searching d:/marmalade/7.4/modules/iwgx/lib/x86\iwgx_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwgl/lib/x86\iwgl_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwgeom/lib/x86\iwgeom_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwresmanager/lib/x86\iwresmanager_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwgxfont/lib/x86\iwgxfont_ttf_d.lib:
1>      Searching d:/marmalade/7.4/modules/third_party/tiniconv/lib/x86\tiniconv_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwui/lib/x86\iwui_d.lib:
1>      Searching d:/marmalade/7.4/modules/iwhttp/lib/x86\iwhttp_d.lib:
1>      Searching d:/marmalade/7.4/extensions/s3etxmpp/lib/x86\s3eTxmpp_d.lib:
1>      Searching d:/marmalade/7.4/s3e/lib/x86\s3e_cpp_d.lib:
1>      Searching d:/marmalade/7.4/s3e/lib/x86\s3e_d.lib:
1>      Searching d:/marmalade/7.4/s3e/lib/x86\s3e_api_iwgl.lib:
1>      Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\OLDNAMES.lib:
1>      Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\LIBCMTD.lib:
1>      Searching C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x86\uuid.lib:
1>      Searching C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x86\kernel32.lib:
1>  
1>  Finished searching libraries
1>XMPPController.obj : error LNK2019: unresolved external symbol "public: __thiscall txmpp::XmppThread::XmppThread(void)" (??0XmppThread@txmpp@@QAE@XZ) referenced in function "public: void __thiscall XMPPController::Init(void)" (?Init@XMPPController@@QAEXXZ)
1>XMPPController.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall txmpp::XmppThread::~XmppThread(void)" (??1XmppThread@txmpp@@UAE@XZ) referenced in function "public: void __thiscall XMPPController::Init(void)" (?Init@XMPPController@@QAEXXZ)
1>Debug_BarnC_vc12_x86\BarnC.s86 : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Solution

  • Marmalade (the SDK tool chain I am using to build this project) is unable to recognize .cc files as source files. I changed them to .cpp and they're getting identified. However there's a lot of errors still present in the library, but at least I know how to solve them. Thanks for the help.