undefined reference to `__imp_ WSASend / WSARec / WSASocketW
-
Hi all,
I am trying to port a Qt widgets project from Linux (where it compiles flawlessly) to Windows (MinGW, installed with Qt installer) where my experience is fairly limited.
I am stuck with the error undefined reference to `_imp WSASend'.
.pro file and compiler output are below.
Help is highly appreciated, thanks in advance.
Brgds
AxelQT += core gui QT += quickcontrols2 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++11 CONFIG += c++17 WIN64 { INCLUDEPATH += ../../../Win64/include LIBS += -L../../../Win64/libs -lcurl LIBS += -lwsock32 # LIBS += -L../../../Win64/libs -ljsoncpp # LIBS += -L$$PWD../../../Win64/libs/jsoncpp.lib # LIBS += -L C:/Users/User/Documents/Win64/libs -ljsoncpp # LIBS += -lstdc++fs # LIBS += -L ../../../Win64/libs -lboost_date_time # LIBS += -L ../../../Win64/libs -lboost_system LIBS += -L../../../Win64/libs -lQXlsx CONFIG += static SOURCES += \ ../../../Win64/src/json/json_reader.cpp \ ../../../Win64/src/json/json_value.cpp \ ../../../Win64/src/json/json_writer.cpp HEADERS += \ ../../../Win64/src/json/json_tool.h \ ../../../Win64/src/json/json_valueiterator.inl }else{ LIBS += -lcurl LIBS += -L/usr/local/lib64 -ljsoncpp LIBS += -lstdc++fs LIBS += -lboost_date_time LIBS += -lboost_system LIBS += -L/usr/local/lib64/QXlsx -lQXlsx INCLUDEPATH += /usr/include/glibc-2.0 INCLUDEPATH += /usr/local/include } # Compile defs for WhiteAPI class DEFINES -= WHITEAPI DEFINES += WHITEGUI RESOURCES +=resources.qrc \ ../../../Frontend/BreezeStyleSheets-master/breeze.qrc # 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 += \ ../WhiteEngine/whiteapi.cpp \ ../WhiteEngine/whitedata.cpp \ ../WhiteEngine/whitefile.cpp \ ../WhiteEngine/whitejson.cpp \ ../WhiteEngine/whitelog.cpp \ ../WhiteEngine/whiterequest.cpp \ ../WhiteEngine/whitestatus.cpp \ ../WhiteEngine/whitetimer.cpp \ ../WhiteEngine/whitetools.cpp \ ../WhiteEngine/whitetranslator.cpp \ ../WhiteEngine/apikey.cpp \ apiwizard.cpp \ detailam.cpp \ detailar.cpp \ detailrender.cpp \ importfile.cpp \ main.cpp \ models.cpp \ notyfier.cpp \ whitebar.cpp \ whitebox.cpp \ whiteclient.cpp \ whiteconfig.cpp \ whitegui.cpp \ whitelistpopup.cpp \ whitelogin.cpp \ whitetimerpopup.cpp \ whiteview.cpp HEADERS += \ ../WhiteEngine/WhiteDefs.h \ ../WhiteEngine/WhiteIncludes.h \ ../WhiteEngine/apikey.h \ ../WhiteEngine/whiteapi.h \ ../WhiteEngine/whitedata.h \ ../WhiteEngine/whitefile.h \ ../WhiteEngine/whitejson.h \ ../WhiteEngine/whitelog.h \ ../WhiteEngine/whiterequest.h \ ../WhiteEngine/whitestatus.h \ ../WhiteEngine/whitetimer.h \ ../WhiteEngine/whitetools.h \ ../WhiteEngine/whitetranslator.h \ apiwizard.h \ detailam.h \ detailar.h \ detailrender.h \ importfile.h \ models.h \ notyfier.h \ whitebar.h \ whitebox.h \ whiteclient.h \ whiteconfig.h \ whitegui.h \ whitelistpopup.h \ whitelogin.h \ whitetimerpopup.h \ whiteview.h FORMS += \ apiwizard.ui \ detailam.ui \ detailar.ui \ detailrender.ui \ importfile.ui \ models.ui \ whiteconfig.ui \ whitegui.ui \ whitelistpopup.ui \ whitelogin.ui \ whitetimerpopup.ui \ whiteview.ui INCLUDEPATH += ../WhiteEngine # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target FORMS += \ APIKeyGUI.ui INCLUDEPATH += ../WhiteEngine # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target DISTFILES += FORMS += \ APIKeyGUI.ui \ models.ui INCLUDEPATH += ../WhiteEngine # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target FORMS += \ APIKeyGUI.ui INCLUDEPATH += ../WhiteEngine # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target DISTFILES +=
And here is the compiler output:
g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\WhiteGUI.exe @object_script.WhiteGUI.Release -L..\..\..\Win64\libs -lcurl -lwsock32 -lQXlsx C:\Qt\6.1.2\mingw81_64\lib\libQt6Widgets.a C:\Qt\6.1.2\mingw81_64\lib\libQt6QuickControls2.a C:\Qt\6.1.2\mingw81_64\lib\libQt6Quick.a C:\Qt\6.1.2\mingw81_64\lib\libQt6OpenGL.a C:\Qt\6.1.2\mingw81_64\lib\libQt6Gui.a C:\Qt\6.1.2\mingw81_64\lib\libQt6QmlModels.a C:\Qt\6.1.2\mingw81_64\lib\libQt6Qml.a C:\Qt\6.1.2\mingw81_64\lib\libQt6Network.a C:\Qt\6.1.2\mingw81_64\lib\libQt6Core.a -lmingw32 C:\Qt\6.1.2\mingw81_64\lib\libQt6EntryPoint.a -lshell32 release/whitetools.o:whitetools.cpp:(.text+0x9131): undefined reference to `__imp_WSASocketW'
-
@AxelVienna
Hi. I certainly did not mean to remove linking withwsock
! That would make it worse :) Rather it was just my observation that these functions are supposed to be provided (and needed) for Windows sockets, but something is not found/has gone wrong in trying to link with them, as a pointer to you for what to investigate :)I have never done MinGW, nor Qt on Windows, so sadly I'm not the right person to ask. However, I think you should start by Googling
mingw wsock32
ormingw winsock
. I think you'll see there are quite a lot links to get you into whatever is necessary for Windows sockets with MinGW. Be careful, though, as some of them are real old, like 2004! I have a feeling you'll want something likelibws2_32.a
. Maybe nowadays it's 64-bit and you done want 32, I don't know. You could maybe just give a go at replacinglwsock32
by-lws2_32
, but don't blame me if this is nonsense :)Alternatively, your
-lwsock32
is itself fine after all, and there is a further problem. Go back to using that as you started out, but can you copy & paste the actual text of whatever errors you get exactly for us to look at? -
@AxelVienna
I can only offer a hint as to what I think is the issue. Please don't read too much into what I suggest, I may be mistaken, but it might point you in the right direction.Your "undefined reference to
__imp_ WSASend / WSARec / WSASocketW
" all refer to Windows sockets functions, the-lwsock32
. That bit I'm sure of!Then I have a feeling that the
__imp_...
prefix is what one sees when compiling/linking against MSVC.lib
files. But you are using MinGW. And I don't think you can mix MSVC libraries with MinGW ones. Are you sure that what you have for the-lwsock32
is good for MinGW linking? -
@JonB Hi Jon, thanks for your reply. When I comment out the link command to wsock32, I get even more errors of the same kind. So you are probably right. I got the hint to use this library from another forum. However, in my mingw path there isn’t anything similar to wsock32.dll. Do you have any idea where to get it? Or how to configure an MSVC compile kit?
-
@AxelVienna
Hi. I certainly did not mean to remove linking withwsock
! That would make it worse :) Rather it was just my observation that these functions are supposed to be provided (and needed) for Windows sockets, but something is not found/has gone wrong in trying to link with them, as a pointer to you for what to investigate :)I have never done MinGW, nor Qt on Windows, so sadly I'm not the right person to ask. However, I think you should start by Googling
mingw wsock32
ormingw winsock
. I think you'll see there are quite a lot links to get you into whatever is necessary for Windows sockets with MinGW. Be careful, though, as some of them are real old, like 2004! I have a feeling you'll want something likelibws2_32.a
. Maybe nowadays it's 64-bit and you done want 32, I don't know. You could maybe just give a go at replacinglwsock32
by-lws2_32
, but don't blame me if this is nonsense :)Alternatively, your
-lwsock32
is itself fine after all, and there is a further problem. Go back to using that as you started out, but can you copy & paste the actual text of whatever errors you get exactly for us to look at? -
@JonB said Hi Jon, thank you so much! -lws2_32 did the trick and the whole show is now compiling and running. You get wiser by the day.