静态库能够与任何其他对象链接,而不管C++该对象使用的运行时
我正在尝试确定是否有可能创建一个静态库,该库:
- 内部使用Microsoft/stl,静态发布运行时(/mt)
- 可以链接到不使用/MT的对象(例如,动态DLL释放,静态调试,静态调试,,等等。)
我要工作的特定测试代码如下:
标题:
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
int EncapLibConcatenate(int a, int b);
#ifdef __cplusplus
}
#endif
来源:
#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;
}
}
链接到上述可以预见的是,当不使用 /MT用于链接到上述库的项目时,会导致A /FailifMismatch错误。我想了解任何编译器 /链接器选项以避免此问题。如果不存在,那么也欢迎其他任何方法(例如修改.OBJ COFF文件)。
附带说明,我知道创建动态库是封装库依赖关系的惯用方法。这是关于技术可能性的问题,而不是最佳实践。我还能够通过避免使用标准库(限制到C Runtime和Win32)来创建一个运行时不稳定的静态库。这个问题是专门针对内部使用C ++标准库的静态库(尽管不是在其界面上)。
I am trying to determine if it is possible at all to create a static library that:
- Internally uses Microsoft/STL, static release runtime (/MT)
- 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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论