Important: Please read the Qt Code of Conduct -

Multiple definition of '__imp___C_specific_handler'

  • I'm facing some compilation issues as I've migrated my working cpp-project from VS to QT. The app is using low-level windows sockets API's. In one of my header file I've used struct addrinfo which requires

    #include <ws2tcpip.h>

    Due to which I'm getting these errors


    If I comment this include, the compiler doesn't recognize struct addrinfo as shown below


    Here is my .pro file

    QT += quick
    CONFIG += c++17
    DEFINES += _WIN32_WINNT=0x0602
    LIBS += -LC:/Windows/System32 -lWs2_32
    # You can make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    SOURCES += \
            ClientResponse.cpp \
            Listen.cpp \
            ServerQueries.cpp \
            base64.cpp \
            client.cpp \
            clientlistwrapper.cpp \
            main.cpp \
    RESOURCES += qml.qrc
    # Additional import path used to resolve QML modules in Qt Creator's code model
    # Additional import path used to resolve QML modules just for Qt Quick Designer
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    HEADERS += \
        ClientResponse.h \
        Listen.h \
        ServerQueries.h \
        base64.h \
        client.h \
        clientlistwrapper.h \
    FORMS +=

    P.S: The same projects builds and run on VS flawlessly.

  • @pingal
    This is only a hunch. Your "undefined references" look like symbols from MSVC compiler to me, while you seem to be using MinGW for your compiler/linker?

  • d88d7fc8-6aa0-4c29-828b-23d8d3724aa4-image.png ![a0fc3fc0-7aa0-4f3c-bd37-2a0b773ef31e-image.png](

    I'm using MinGW compiler in QT

  • @pingal
    I know you are. The question is about your use of -lWs2_32. Does that pull in a .a file (MinGW) or a .lib file (MSVC)? Does that have a runtime .DLL file which is MSVC or MinGW? Does the .DLL have any further unsatisfied dependencies?

    Another possibility: you are using 64-bit MinGW. Are you building for 32- or 64-bit? If 64-bit, does -lWs2_32 target 32-bit? Does e.g. apply to your case? The accepted solution there claims -LC:\Windows\system32 <your files> ws2_32.dll works.

    If that is not the issue. I would concentrate initially on the first error message, "multiple definition", and only look at the further errors after resolving that. I would write a tiny standalone program with #include <ws2tcpip.h> and a minimal socket connect() or similar and get that linking successfully. If that works you need to go look at the code you have using sockets, it might have e.g. MSVC-only #ifs which change the behaviour with a non-MSVC compiler that you need to address.

  • @JonB

    Thank you. I have created a tiny standalone executable on QT which identified the problem, as i think the below line was pulling .lib file

    LIBS += -LC:/Windows/System32 -lWs2_32

    I've replaced it with the following and now the app compiled.

    LIBS += -lws2_32

  • @pingal
    That is a funny one! Windows should be case-insensitive, filename-wise. However, it looks like MinGW linker is case-sensitive to some degree.

Log in to reply