Question

I'm following the instructions, which tell me to download msgpack 0.5.4 for C & C++.

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 has been replaced by MSBuild msgpack_vc8.vcxproj. I used Visual studio 2012 to convert the project to have the correct .vcxproj for this. Batch build in Visual studio and running MSBuild gives the same result, so I will speak for both of them from this point on.

After the project is converted, I noticed the project was set to output to .lib, rather than .dll, so I altered that setting to match my needs. When compiling there was one small error:

...\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'

So I changed the line

typedef __int8 int8_t;

to

typedef signed __int8 int8_t;

which solves that minor issue. But then we arrive at where I'm at now. This linker error:

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.4\Debug\MessagePack.dll : fatal error LNK1120: 2 unresolved externals

I've searched for parts of this error:

In sysdep.h:

#define _msgpack_be16(x) ntohs(x)
#define _msgpack_be32(x) ntohl(x)

In 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; }
        }

        

In 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;
}

And that's about all I know. If there's another way of how to obtain the .dll, that would be helpful too. Thank you in advance. :)

Was it helpful?

Solution

You need to link the ws2_32.lib library since ntohl is a winsocket API function.

That should fix the problem!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top