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

  • Home
  • SEARCH
  • 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 6978255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:43:53+00:00 2026-05-27T17:43:53+00:00

I need help access global functions across DLLs/main program. I have a class Base

  • 0

I need help access global functions across DLLs/main program. I have a class Base

Base.h

#ifdef MAIN_DLL
#define DECLSPEC __declspec(dllexport)
#else
#define DECLSPEC __declspec(dllimport)
#endif


class Base {
private:
    DECLSPEC static Filesystem * filesystem;
    DECLSPEC static Logger * logger;
    DECLSPEC static System * system;

public:

    static void setFilesystem(Filesystem * filesystem_);
    static void setApplication(Application * application_);
    static void setLogger(Logger * logger_);
    static void setSystem(System * system_);

    static Filesystem * fs() { return filesystem; }
    static Logger * log() { return logger; }
    static System * sys() { return system; }

};

main.cpp (main application) (MAIN_DLL is predefined here)

Filesystem * Base::filesystem = 0;
Logger * Base::logger = 0;
System * Base::system = 0;

When I access from the dll:

System * system = Base::sys();
if(system == 0) std::cout << "Error";

Thanks,
Gasim

  • 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-05-27T17:43:54+00:00Added an answer on May 27, 2026 at 5:43 pm

    This is system dependent, but you’ll have to ensure that the symbols in the DLL containing the definitions of the member functions and static member data correctly exports the symbols, and that the DLL using them correctly imports them. Under Linux, this means using the -E option when linking the executable (if the symbols are defined in the executable); under Windows, you usually have to use conditionally compiled compiler extensions, see __declspec; Microsoft compilers do not support DLL’s in standard C++.

    EDIT:

    Here’s an example that works on my system (VC 2010):

    In A.h:

    #ifndef A_h_20111228AYCcNClDUzvxOX7ua19Fb9y5
    #define A_h_20111228AYCcNClDUzvxOX7ua19Fb9y5
    
    #include <ostream>
    
    #ifdef DLL_A
    #define A_EXPORT __declspec(dllexport)
    #else
    #define A_EXPORT __declspec(dllimport)
    #endif
    
    class A_EXPORT InA
    {
        static std::ostream* ourDest;
    public:
        static void setDest( std::ostream& dest );
        static std::ostream* getStream() { return ourDest; }
    };
    #endif
    

    In A.cpp:

    #include "A.h"
    
    std::ostream* InA::ourDest = NULL;
    
    void
    InA::setDest( std::ostream& dest )
    {
        ourDest = &dest;
    }
    

    In main.cpp:

    #include <iostream>
    #include "A.h"
    
    int
    main()
    {
        InA::setDest( std::cout );
        std::cout << InA::getStream() << std::endl;
        return 0;
    }
    

    Compiled and linked with:

    cl /EHs /LDd /DDLL_A A.cpp
    cl /EHs /MDd main.cpp A.lib
    

    As I understand it (I’m more a Unix person), all of the .cpp which
    become part of the dll should have /DDLL_A in the command line which
    invokes the compiler; none of the others should. In Visual Studios,
    this is usually achieved by using separate projects for each dll and
    each executable. In the properties for the project, there’s an entry
    ConfigurationProperties→C/C++→Preprocessor→Preprocessor
    Definitions; just add DLL_A there (but only in the one project that
    generates A.ddl).

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

Sidebar

Related Questions

I need help understanding some C++ operator overload statements. The class is declared like
i need help with disk_total_space function.. i have this on my code <?php $sql=select
need to implement a global error handling, so maybe you can help out with
I have a very basic question and need help. I am trying to understand
I need help in creating an query interface with access database. In brief, with
I need help in writing a C# script which can access a secured shared
Need help pretty soon on this..... I have a Gridview in which the columns
I need help understanding a practice exam problem for a CS class in python.
I need help! :-) I have an application and want to make it modular,
I need help with a question that I could not answer yet. I have

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.