Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Can't link to Windows library
QtWS25 Last Chance

[Solved] Can't link to Windows library

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 13.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RickH
    wrote on last edited by
    #1

    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
    
    1 Reply Last reply
    0
    • L Offline
      L Offline
      loladiro
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gedd
        wrote on last edited by
        #3

        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@

        Gedd

        1 Reply Last reply
        0
        • R Offline
          R Offline
          RickH
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • R Offline
            R Offline
            RickH
            wrote on last edited by
            #5

            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
            
            1 Reply Last reply
            0
            • EddyE Offline
              EddyE Offline
              Eddy
              wrote on last edited by
              #6

              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.

              Qt Certified Specialist
              www.edalsolutions.be

              1 Reply Last reply
              0
              • L Offline
                L Offline
                loladiro
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  gedd
                  wrote on last edited by
                  #8

                  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 !!!!

                  Gedd

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    RickH
                    wrote on last edited by
                    #9

                    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
                    
                    1 Reply Last reply
                    0
                    • EddyE Offline
                      EddyE Offline
                      Eddy
                      wrote on last edited by
                      #10

                      Glad to hear you like Qt!

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

                      Qt Certified Specialist
                      www.edalsolutions.be

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved