Implicit declaration of function 'getaddrinfo' on MinGW

后端 未结 3 433
醉梦人生
醉梦人生 2020-12-17 02:43

I have a C program that uses getaddrinfo(). It works as expected on Linux and Mac OS X.

I\'m in the middle of porting it to Windows.

When I comp

3条回答
  •  萌比男神i
    2020-12-17 03:01

    If you want to make your code compiler-wide you should actually also define NTDDI_VERSION with the same OS version as _WIN32_WINNT. Without that defining only _WIN32_WINNT will not let you to use getaddrinfo() with some compilers (i.e. Watcom). It is better to wrap it in the same way as Windows SDK does:

    #define _NTDDI_VERSION_FROM_WIN32_WINNT2(ver)    ver##0000
    #define _NTDDI_VERSION_FROM_WIN32_WINNT(ver)     _NTDDI_VERSION_FROM_WIN32_WINNT2(ver)
    
    #ifndef _WIN32_WINNT
    #  define _WIN32_WINNT 0x501
    #endif
    #ifndef NTDDI_VERSION
    #  define NTDDI_VERSION _NTDDI_VERSION_FROM_WIN32_WINNT(_WIN32_WINNT)
    #endif
    

提交回复
热议问题