This is the second day I'm struggling with this nasty issue. Test code I try to compile:
#include <windows.h>
#include <setupapi.h>
#include <initguid.h>
#include <devguid.h>
int main(void)
{
    HDEVINFO device_info_set = SetupDiGetClassDevs(
        (const GUID *) &GUID_DEVCLASS_PORTS,
        NULL,
        NULL,
        DIGCF_PRESENT);
        
    return 0;
}
And mingw output:
loleq@loleq-Pc MINGW32 /c/Users/loleq/Downloads/openpst/openpst/sahara/lib/libopenpst/lib/serial/examples
$ gcc --version
gcc.exe (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 5.3.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
loleq@loleq-Pc MINGW32 /c/Users/loleq/Downloads/openpst/openpst/sahara/lib/libopenpst/lib/serial/examples
$ gcc -lsetupapi -lhid  test.c
C:\opt\msys2_64\tmp\ccJZHvjA.o:test.c:(.text+0x36): undefined reference to `_imp__SetupDiGetClassDevsA@16'
collect2.exe: error: ld returned 1 exit status
Host system is Win7 64bit, I didn't install any additional libraries, i.e. DDK or so... I believe missing reference should be handled by libsetupapi.a (-lsetupapi) which of course presents in MinGW libraries. Any suggestions? BTW: MinGW I'm using right now is provided by Qt.
 
     
    