[Solved] Can't link to Windows library



  • Hello all. After much reading and hacking, I have a program that compiles, but doesn't link. The program is the client half of a tcp connection. It complains that it can't find a library:

    readevalprintloopthread.obj:-1: error: LNK2019: unresolved external symbol __imp__freeaddrinfo@4 referenced in function "public: void __thiscall ReadEvalPrintLoopThread::ConnectToServer(void)" (?ConnectToServer@ReadEvalPrintLoopThread@@QAEXXZ)

    I have a pure Microsoft solution somebody gave me, and I can make that solution stop building by hiding a certain library, so I think I've found the library it can't find. (WS2_32.lib) I checked my lib path based on this suggestion on the net:

    http://stackoverflow.com/questions/718447/adding-external-library-into-qt-creator-project

    but the lib path seems to be there.

    Doesn't anybody know why I can't find this library?

    (I'm sure somebody will ask me, so I'll say now: I'm using Microsoft socket facilities and not Qt socket facilities because the objective is to show somebody that I understand Unix/Windows tcp. I wrote it in Qt Creator so I could use the other facilities.)

             Regards, Rick


  • Are you using qmake? If yes, could you show us the LIBS statements?



  • If your solution is pure Ms, try to just add WS2_32.lib to the LIBS statement

    @win32:LIBS += -lWS2_32@

    or

    @win32:LIBS += WS2_32.lib@



  • Hi. I made a similarly named post over in General, but I've realized this is a better place for it, and I've figured out a simpler way to ask my question.

    Can anybody compile and link this? :

    @
    #include <QtCore/QCoreApplication>
    #include <ws2tcpip.h>
    int main(int argc, char *argv[]) {
    QCoreApplication a(argc, argv);
    struct addrinfo * servinfo = NULL;
    freeaddrinfo(servinfo);
    return a.exec();
    }
    @

    When I try, I can't link it. :

    LNK2019: unresolved external symbol __imp__freeaddrinfo@4 referenced in function _main

              Regards, 
    
              Rick
    

    EDIT: please use @-tags for code highlight, Gerolf



  • Hi. I am using Qt Creator. I suspect that if I could find this LIBS of which you speak, my problems would be over.

    I'm willing to say "Qt Creator doesn't handle this correctly. I should go one level lower, closer to the metal, and use qmake." Is that what I should say?

    I figured out a way to ask my question more simply, and so I did, over in the Tools forum. Same title.

             Regards, Rick

  • Moderators

    I merged this 2 threads because this is about the same problem.

    Could you use @tags for your code please? Or use button with <> on it on top of editor. It makes it more readible for others.



  • The LIBS directive has to go into your .pro file.



  • bq. Hi. I made a similarly named post over in General, but I’ve realized this is a better place for it, and I’ve figured out a simpler way to ask my question.
    Can anybody compile and link this? :
    ....
    When I try, I can’t link it. :
    LNK2019: unresolved external symbol __imp__freeaddrinfo@4 referenced in function _main

    I have the same error without change anything but when i add @win32:LIBS += -lWS2_32@ to the .pro file it works fine !!!!



  • I will use @tags the next time I include code. And I guess two threads for the same topic is considered undesireable. I won't do that again.

    Adding the line to ...pro worked. I wasn't aware that I had access to qmake through that file.

    This environment is very pleasant. There seem to be fewer unnecessary obstacles than in other environments.

    Thanks for your help.

           Rick

  • Moderators

    Glad to hear you like Qt!

    Please could you edit your title and add [Solved] in front of it?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.