title: LNK2001: unresolved external symbol, when trying to call method of object from another DLL
body: <p>I have two modules, each with own class and with own object. Each module is compiled to a DLL. I want to make a "cross-DLL" method call, having pointer to the object of another class, but linker doesn't allow to do this (MSVC++ 2008).</p>
  
  <p>More specifically:</p>
  
  <ul>
  <li>there is calledModule.cpp, that has calledClass, and object of this class (calledObject); class has calledMethod, which I want to call; module is compiled to DLL and becomes (surprise!) calledLib.dll.</li>
  <li>there is callingModule.cpp, that has callingClass; among other things, the class has the attribute, which is a pointer to the calledObject; module is compiled to DLL callingLib.dll; the pointer on calledObject is set in the constructor.</li>
  </ul>
  
  <p>I'm able to compile the whole code. The trouble comes when the linker starts. I'm getting the following: 
  moduleCalling.obj : error LNK2001: unresolved external symbol "public: void __thiscall classCalled::methodCalled ..."</p>
  
  <p>I don't use any declspec things, so nothing is exported from the calledLib.dll.</p>
  
  <p>The method that I'm calling (methodCalled) is present in the implementation, its prototype is correctly declared in header. The classCalled is a "basic" class, not inherited from anything.
  Moreover, the whole project compiles and working correctly, when I declare methodCalled as a virtual...</p>
  
  <p>I have troubles understanding, why I can't call the method of the object in a "normal" way from another DLL? Why declaring it as a "virtual" helps? Anyone knows? I have some guesses, but expert answer will help a lot to understand this stuff.</p>
  
  <p>P.S.: I'm using MSVC++ 2008.</p>
  
  <p>Thanks!</p>
  
  <p>Update: adding code snippet, which reflects, how the code looks like.</p>
  
  <pre><code>// part of calledLib.dll
  // moduleCalled.h
  
  class classCalled {
    public:
      int methodCalled() { return 1 };
  };
  
  // ---------------------------------------------------------------
  // part of callingLib.dll
  // moduleCalling.h
  
  #include "moduleCalled.h"
  
  class classCalling {
    public:
      classCalled* ref;
      void justSomeMethod();
  };
  
  // ---------------------
  // moduleCalling.cpp
  
  #include "moduleCalling.h"
  
  void classCalling::justSomeMethod() {
    ref = new classCalled();
    int a = ref-&gt;methodCalled(); // &lt;--- this is not allowed by linker,
                                 // unless methodCalled is made virtual.
  }
  </code></pre>