Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9240425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:11:16+00:00 2026-06-18T08:11:16+00:00

I have two modules, each with own class and with own object. Each module

  • 0

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).

More specifically:

  • 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.
  • 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.

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 …”

I don’t use any declspec things, so nothing is exported from the calledLib.dll.

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…

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.S.: I’m using MSVC++ 2008.

Thanks!

Update: adding code snippet, which reflects, how the code looks like.

// 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->methodCalled(); // <--- this is not allowed by linker,
                               // unless methodCalled is made virtual.
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:11:17+00:00Added an answer on June 18, 2026 at 8:11 am

    Linker links pieces of code from various modules. If you have a call from one module to another, linker has to know in which other module the function you’re invoking is implemented and substitute the call by the real address. This is a very rough picture, but it’s enough to understand what is going on.

    In your case the linker has to know that your function is located in calledLib.dll. Therefore you have to link with something that refers to calledLib.dll. This something is called an import library. It’s name should be calledLib.lib. In order to generate it you either should write a .def file, but it’s difficult for class methods, since class methods names used by linker look very different from what they look like in your C++ code. Or you can use declspecs. It will generate the proper calledLib.lib, which you will have to link with your callingLib.dll.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have two Modules on each modules i have models with table class,
Ok I have two modules, each containing a class, the problem is their classes
I have these two modules : package G1; sub new { my $class =
I have written a module similar to the following: module One class Two def
I have two modules which imports each other. Haskell doesn't support recursive modules. So
If I have two modules, each has implemented its preprocess_node hook. Then which one
I have a model which is used by two modules. I don't want to
I have an IntelliJ IDEA project contains two Scala modules M1 and M2. Each
say I have two 'modules'. For instance the hardware-interface layer of a RS-232 port
I am working on a transliteration tool. I have two modules lexer and translator.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.