【发布时间】:2018-06-02 16:09:35
【问题描述】:
在安装和使用 google protobuf 库 (Install Protobuf On Windows) 的说明页面上,它指出:
如果您的项目本身是一个供第三方软件使用的 DLL,我们建议您不要在库的公共接口中公开协议缓冲区对象,并且您将协议缓冲区静态链接到您的库中强>。
我想知道如何做到这一点。据我所知,您可以通过两种方式构建 google protobuf:静态和动态。
如果您动态构建它,您将面临上述问题。如果您静态构建它,那么您将使用 多线程 (/MT) 的 Visual Studio 中的代码生成类型。这意味着在我的 dll 库(使用 多线程 DLL (/MD) 构建的地方)中,您将收到以下链接器错误:
错误 LNK2038:检测到“RuntimeLibrary”不匹配:值“MTd_StaticDebug”与 Emulator.obj 中的值“MDd_DynamicDebug”不匹配
现在有几个问题涉及如何解决这个问题:
- error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj
- Mismatch Detected for 'RuntimeLibrary'
- (非常相似)Errors when linking to protobuf 3 on MSVC 2013
但答案通常是,更改您的库以匹配其他库的构建类型。问题是,我不想那样做,我想要一个 DLL。我想静态链接google protobuf,如他们的文档中所述。 我怎样才能做到这一点?
【问题讨论】:
标签: c++ dll linker protocol-buffers linker-errors