1

I use Visual Studio 2017. I have a multi-project solution (c++). There is a project which creates an executable (core app) and projects which create dynamic libraries (plugins). A core app loads plugins at runtime using LoadLibrary and GetProcAddress functions. A core app defines an object which contains a map, here is a simplified definition:

class T
{
public:
    void fun(const std::string& key)
    {
        ++data_[key];
    }
private:
    std::map<std::string, int> data_;
};

T object is defined statically in the core app and registered in the plugin (via pointer) which uses it this way:

void Plugin::fun()
{
    t->fun(key);
}

The memory allocation takes places when a plugin calls the function but deallocation is performed in the core app. It leads to the following error after closing the app:

enter image description here

That error is not present when I use T object only from the core app.I have found a similar topic but there an error message is a little bit different. A code generation property for the core app and plugin looks this way:

enter image description here

What does it mean that Runtime Library record is set to different options with bold font ? How should I set Runtime Library in the core app and plugin to fix the problem ?

Irbis
  • 1,432
  • 1
  • 13
  • 39

1 Answers1

2

To see what runtime library you are actually using, you need to select just one platform and configuration (the ones you are building for) from the dropdowns. The runtime library needs to be Multi-Threaded DLL (or Multi-Threaded Debug DLL for Debug builds) for both your app and your plugin, and the configuration you are building for (Debug or Release) also needs to match.

The memory allocation takes places when a plugin calls the function but deallocation is performed in the core app.

This is fragile. I would recommend both allocating and deallocating in the plugin or both in the app, if you can arrange it.

Paul Sanders
  • 24,133
  • 4
  • 26
  • 48