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 8989119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:10:32+00:00 2026-06-15T22:10:32+00:00

I feel this issue may have a simple solution that’s just not obvious to

  • 0

I feel this issue may have a simple solution that’s just not obvious to me – I have a config class that is used to store various configuration options loaded from an ini file, among other places. In my application, I have a library and client, and 2 configurations – build the library as a DLL and have the client link dynamically, or build them both together as a single binary. So how can I have/use my config object in both the library and client? If I include the config class definition in both, I assume it will give me link errors due to redefinitions.

  • 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-15T22:10:33+00:00Added an answer on June 15, 2026 at 10:10 pm

    If I include the config class definition in both, I assume it will give me link errors due to redefinitions.

    No, it won’t. Windows DLLs do not respect the one definition rule. Basically, in Windows, ODR stops at the module boundary, i.e., ODR is respected within an executable and within a DLL, but not across them. Whether that’s a good thing or not is not relevant, that’s just how it is. So, you can include the definition of your config class in both the DLL and the executable. However, there will be two separate instances of the singleton (as I assume it is a singleton class, as config classes usually are), one in each module. In that sense, it won’t be a true singleton, at least, not across the modules.

    If you want a true singleton across the modules, you’ll have to do a bit more work. You have two choices: master-slave or merging (or a “daisy chain”).

    The first option is to designate one module (e.g., the executable) as the module that instantiates (and keeps) the singleton object, and then you pass a pointer to that instance to all the “slave” modules which can then use it via a common interface (so both modules have the same declaration for the config class, but only one module creates it and passes it to the others). It would look something like this:

    In the header file “config_class.h”:

    class ConfigClass {
    
      // a bunch of declarations...
    
      public:
        static ConfigClass& getInstance();  // the access-point for the singleton.
    };
    
    #ifdef MY_LIB_NOW_BUILDING_MASTER
    
    extern "C" __declspec(dllimport) void setConfigClassInstance(ConfigClass* pobj);
    
    #else
    
    extern "C" __declspec(dllexport) void setConfigClassInstance(ConfigClass* pobj);
    
    #endif 
    

    In the cpp file “config_class.cpp”:

    #include "config_class.h"
    
    // a bunch of definitions for the config_class member functions.
    
    #ifdef MY_LIB_NOW_BUILDING_MASTER
    
    ConfigClass& ConfigClass::getInstance() {
      static ConfigClass instance( /*  */ );
      return instance;
    };
    
    #else
    
    static ConfigClass* masterInstance;
    
    void setConfigClassInstance(ConfigClass* pobj) {
      masterInstance = pobj;
    };
    
    ConfigClass& ConfigClass::getInstance() {
      return *masterInstance;
    };
    
    #endif
    

    where, in the above example, you would call setConfigClassInstance from the master module (most likely the main executable) to set the config object for the DLLs, but make sure the DLLs don’t require the config class during their static initialization (loading).

    The second option is to either merge or daisy-chain your singletons. In this case, each module creates its own singleton instance, but then, using a similar scheme as above, they pass pointers to each other’s instances, allowing them to be either merged into one instance (cross-linked), or you chain them together (e.g., like a circular linked-list or ring-list) and you dispatch the calls to the appropriate instance.

    I think that for your application, the first option is probably the easiest.

    N.B.: In non-Windows environments, the situation is entirely different, and none of the above applies.

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

Sidebar

Related Questions

I feel like this might be really simple but I'm just not getting it
I feel like this is something I should already know, but I'm just not
I feel like I may be over-thinking this solution... so I figured I'd get
I know this may not be exactly a coder question, but I feel it
I know that you guys may feel that this is repetitive question. But I'm
I have a script being run in a document that may or may not
I am faced with the following issue and at this point I feel like
I feel this is not a very good question to post on SO, but
I feel like this should be obvious to me, but for some reason I
I feel like this is quite delicate, I have various folders whith projects I

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.