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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:15:32+00:00 2026-05-15T09:15:32+00:00

I’m looking to hot plug a library of C++ code. I’m interested in having

  • 0

I’m looking to “hot plug” a library of C++ code. I’m interested in having this technique work cross platform between Linux/Mac/Windows. Basically I want to have the main program #include “StateMachine.h” which defines all callable interfaces. Then at runtime and DURING EXECUTION load and unload StateMachineLibrary.a to have my application use different state machines.

One thought I have is maybe do something like write a wrapper that loads this compiled code in to my own malloc’d memory and creates function pointers in to that memory?

Motivation is that the State Machine portions of my project will be frequently changing and need recompilation, also would allow the main app to continue running with different State Machines being loaded. I’m hoping to use a “hot-pluggable” library INSTEAD OF something like Lua scripts due to some concerns, so considering that as an alternative has already been explored.

  • 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-15T09:15:33+00:00Added an answer on May 15, 2026 at 9:15 am

    Define a base interface and derive your implementations from it. Put these into dynamic libraries (DLL/SO) and load them at runtime. The library will just need a static factory function to deliver an instance of its implementation to you.

    // shared
    class Base {
     public:
       virtual void DoTheWork() = 0;
    };
    
    // within the DLL/SO
    class Hotplugged : public Base {
      public:
       virtual void DoTheWork() {
          std::cout<<"I got hotplugged!"<<std::endl;
       }
    };
    
    extern "C" Base* CreateIt() {
      return new Hotplugged();
    } 
    
    // within the app (sample for Windows/MSVC)
    ... ::LoadLibrary("mydll");
    Base* (*fpCreateIt)() = (Base*(*)())::GetProcAddress(... "CreateIt");
    // call the function pointer to obtain a Base instance
    Base* mybase = fpCreateIt();
    
    // prints the above text
    mybase->DoTheWork(); 
    delete mybase;
    

    Note: this is just a sketch. It has some flaws, for example I’m ignoring ownership semantics, and no actual checks are done if the DLL we just loaded is binary compatible with us. Think about it a bit, or look for existing implementations (some are mentioned in other responses).

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

Sidebar

Related Questions

No related questions found

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.