2014-02-11 51 views
1

我在關注the instructions,它告訴我要下載msgpack 0.5.4 for C & C++爲C和C++安裝MessagePack實現時的鏈接器錯誤

On Windows, download source package from here and extract it. Open msgpack_vc8.vcproj or msgpack_vc2008 file and build it using batch build. It builds libraries in lib/ folder and header files in include/ folder.

You can build using command line as follows:

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.0\vc\include\stdint.h(8): error C2371: 'int8_t' : redefinition; different basic types 
...msgpack-0.5.4\src\msgpack\sysdep.h(23) : see declaration of 'int8_t' 

所以我改了行

typedef __int8 int8_t; 

typedef signed __int8 int8_t; 

這解決了小問題。但是,我們到達現在的位置。這個連接錯誤:

objectc.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _msgpack_pack_array 
unpack.obj : error LNK2001: unresolved external symbol [email protected] 
objectc.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _msgpack_pack_array 
unpack.obj : error LNK2001: unresolved external symbol [email protected] 
...\msgpack-0.5.4\Debug\MessagePack.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; } 
     } 

在unpack.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的方法,那也是有幫助的。先謝謝你。 :)

回答

1

您需要鏈接ws2_32.lib庫,因爲ntohl是一個winsocket API函數。

這應該解決問題!