Sunday, 14 December 2014

Using libmicrohttpd with MSVC

Windows is not POSIX compliant. Attempting to include files like sys/select.h will not work because they don't exist. Here's a step-by-step guide to get the libmicrohttpd demo working on MSVC.
  1. Add the include directory.
  2. Make sure code generation runtime library is set to multi-threaded DLL (/MDd or /MD).
  3. Include the library directory (/lib and /bin).
  4. Add dependency libmicrohttpd.dll.a and Ws2_32.lib
  5. Go to Linker > All Options and make sure /SAFESH is not Yes. (Am using libmicrohttpd-0.9.17-w32, not sure for newer versions).
  6. Finally, include also the following.
#ifndef MHD_PLATFORM_H
#define MHD_PLATFORM_H
#include <winsock2.h> // socket related definitions
#include <ws2tcpip.h> // socket related definitions
#include <sys/types.h>
typedef SSIZE_T ssize_t; //Windows type to unix type
typedef UINT64 uint64_t; //Windows type to unix type
typedef UINT16 uint16_t; //Windows type to unix type
#endif
#include <microhttpd.h>
...

That should be about it.

3 comments:

  1. libmicrohttpd-0.9.17-w32 has known vulnerabilities, it is strongly advised to use one of the newer versions. For further information check out this link.

    ReplyDelete
  2. It's also easy to run it with MinGW-GCC under windows. the "typedef SSIZE_T ssize_t" is not needed in this case.

    ReplyDelete
  3. Thank You and I have a tremendous offer you: Where Do You Get The Money To Renovate A House home renovation planning

    ReplyDelete