安装C和C++的MessagePack实现时发生链接器错误
Linker error when installing MessagePack implementation for C and C++
我正在按照指示下载适用于C&C++
在Windows上,从这里下载源程序包并提取它。打开msgpack_vc8.vcproj或msgpack_vc2008文件并使用批处理构建它。它在lib/文件夹中构建库,在include/文件夹中生成头文件。
您可以使用以下命令行进行构建:
vcbuild msgpack_vc2008.vcproj
dir lib % DLL files are here
dir include % header files are here
vcbuild msgpack_vc2008.vcproj已被MSBuild msgpack_vc8.vcxproj替换。我使用Visual studio 2012将该项目转换为正确的.vcxproj。Visual studio中的批量构建和运行MSBuild会得到相同的结果,所以从现在开始,我将为他们两个说话
转换项目后,我注意到项目被设置为输出到.lib,而不是.dll,所以我更改了该设置以满足我的需求。编译时出现一个小错误:
...microsoft visual studio 11.0vcincludestdint.h(8): error C2371: 'int8_t' : redefinition; different basic types
...msgpack-0.5.4srcmsgpacksysdep.h(23) : see declaration of 'int8_t'
所以我换了
typedef __int8 int8_t;
至
typedef signed __int8 int8_t;
这解决了这个小问题。但后来我们到达了我现在的位置。此链接器错误:
objectc.obj : error LNK2019: unresolved external symbol __imp__ntohl@4 referenced in function _msgpack_pack_array
unpack.obj : error LNK2001: unresolved external symbol __imp__ntohl@4
objectc.obj : error LNK2019: unresolved external symbol __imp__ntohs@4 referenced in function _msgpack_pack_array
unpack.obj : error LNK2001: unresolved external symbol __imp__ntohs@4
...msgpack-0.5.4DebugMessagePack.dll : fatal error LNK1120: 2 unresolved externals
我已经搜索了这个错误的部分:
在sysdep.h中:
#define _msgpack_be16(x) ntohs(x)
#define _msgpack_be32(x) ntohl(x)
在object.c:中
case MSGPACK_OBJECT_ARRAY:
{
int ret = msgpack_pack_array(pk, d.via.array.size);
if(ret < 0) { return ret; }
msgpack_object* o = d.via.array.ptr;
msgpack_object* const oend = d.via.array.ptr + d.via.array.size;
for(; o != oend; ++o) {
ret = msgpack_pack_object(pk, *o);
if(ret < 0) { return ret; }
}
在开箱中。c:
static inline int template_callback_array(unpack_user* u, unsigned int n, msgpack_object* o)
{
o->type = MSGPACK_OBJECT_ARRAY;
o->via.array.size = 0;
o->via.array.ptr = (msgpack_object*)msgpack_zone_malloc(u->z, n*sizeof(msgpack_object));
if(o->via.array.ptr == NULL) { return -1; }
return 0;
}
我只知道这些。如果有另一种方法可以获得.dll,那也会很有帮助。提前谢谢。:)
由于ntohl是一个winsocket API函数,因此需要链接ws2_32.lib库。
这应该能解决问题!
相关文章:
- 静态数据成员的问题-修复链接错误会导致编译器错误
- Visual Studio mkl_link_tool.exe链接错误
- C++ 实现模板单例类时出现链接错误
- 使用类模板的方法链接错误
- MySQL C++连接器链接错误
- VS 2015 链接错误 无法构建依赖于 libcurl 的项目
- 运行 C++ 单元测试时LNK2005链接错误
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 链接错误,包括我创建的相同头文件 - C++
- 在Embarcadero C++ Builder中生成的DLL未解决的外部链接错误
- 使用标头保护的多个定义链接错误
- 链接错误:未定义对 stdscr 和 wgetch 的引用
- 使用 Vivek 的 Vcam / 捕获源过滤器构建/链接错误
- 升压program_options中的链接错误
- 使用 g++ 预处理器进行替换会导致链接错误
- 在调试配置中编译工作正常,但发布会给出链接错误
- 相邻矩阵设置链接错误
- 包含常量变量并包含在多个文件中的标头的链接错误
- C++链接错误,我理解但无法解决
- 是什么导致macOS Mojave上的GoogleTest链接错误