'Static library able to link with any other object, regardless of C++ runtime used by that object

I am trying to determine if it is possible at all to create a static library that:

  1. Internally uses Microsoft/STL, static release runtime (/MT)
  2. Can be linked to objects not using /MT (e.g., Dynamic DLL Release, Static Debug, etc.)

The specific test code I'm trying to get working is as follows:

Header:

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

    int EncapLibConcatenate(int a, int b);

#ifdef __cplusplus
}
#endif

Source:

#include "EncapLib.h"
#include <string>

int EncapLibConcatenate(int a, int b)
{
    try {
        return std::stoi(std::to_string(a) + std::to_string(b));
    } catch (...) {
        return 0;
    }
}

Linking to the above predictably results in a /FAILIFMISMATCH error when not using /MT for the project that links to the above library. I would like to learn of any compiler / linker options to circumvent this issue. If such do not exist, then any other approaches (such as modifying the .obj COFF files post-build) would also be welcome.

As a side note, I am aware that creating a dynamic library is the idiomatic approach to encapsulating library dependencies; this is a question regarding technical possibilities, not best practices. I have also been able to create a runtime-agnostic static library by eschewing any use of the standard library (restricting to C runtime and win32). This question is specifically about a static library that uses the C++ standard library internally (though pointedly not at its interface).



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source