Results 1 to 19 of 19

Thread: using libcurl in QT with Mingw in Windows

  1. #1
    Join Date
    Feb 2006
    Posts
    91
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default using libcurl in QT with Mingw in Windows

    I used to compile a qt program that used libcurl by adding libs+= -lcurl after installing libcurl in linux. But now that I want to compile the same program in windows I am having problems. Even though I seem to have libcurl.dll in the mingw's bin folder several attempts have gone in vain.
    What are the steps that have to be followed to compile a QT program that uses libcurl in Windows with mingw. Do we still have to add the Libs+= -lcurl in the .pro file of the project ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using libcurl in QT with Mingw in Windows

    Quote Originally Posted by ct
    Do we still have to add the Libs+= -lcurl in the .pro file of the project ?
    Yes.

    MinGW needs a libcurl.a file for that DLL. Do you have it? How did you compile curl?

  3. #3
    Join Date
    Feb 2006
    Posts
    91
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using libcurl in QT with Mingw in Windows

    Well I downloaded "curl-7.13.0-win32-ssl-devel-mingw32.zip" which already had libcurl.dll,curl.exe,libcurldll.a,libcurl.a files.
    Do I again need to compile if I already have those binaries..( I think after compiling we will get the same binaries).

    I put them in \bin folder of mingw and even had the two files of openssl namely libeay32.dll and libssl32.dll in the same folder. Even copied the 'curl' folder inside the curl package and put it into the mingw include folder..

    finally I have
    LIBS+= -lcurl in my .pro file

    now when I compile I get weird error...at the end saying something like

    C:\Dev-Cpp\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw 32\bin\ld.exe: cannot f
    ind -lcurl
    collect2: ld returned 1 exit status
    make: *** [app.exe] Error 1

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using libcurl in QT with Mingw in Windows

    Try:
    Qt Code:
    1. LIBS += -L<path to a directory with libcurl.a> -lcurl
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Feb 2006
    Posts
    91
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using libcurl in QT with Mingw in Windows

    Yes it worked ...could you also tell why the path..I already have the path in the $PATH of the system...
    Also something about the big L and why it is needed as I already have -lcurl saying curl library is being used.
    Humans make mistake because there is really NO patch for HUMAN STUPIDITY

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using libcurl in QT with Mingw in Windows

    Quote Originally Posted by ct
    I already have the path in the $PATH of the system...
    PATH is for binaries, not libraries.

    Quote Originally Posted by ct
    Also something about the big L and why it is needed as I already have -lcurl saying curl library is being used.
    -L<dir> tells the linker that it should look for libraries also in <dir>, while -l<lib> tells it to link with the library <lib>.

  7. #7
    Join Date
    Oct 2008
    Location
    Europe
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: using libcurl in QT with Mingw in Windows

    hi,
    I know the thread is old, but could you guys tell me how to compile an application with libcurl ? Its very fuzzy to me

    thank you very much

  8. #8
    Join Date
    Oct 2008
    Location
    Europe
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: using libcurl in QT with Mingw in Windows

    Please, anyone ?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using libcurl in QT with Mingw in Windows

    Do you have libcurl installed?

  10. #10
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Thanks
    48
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using libcurl in QT with Mingw in Windows

    for starters,
    I compiled libcurl with SSL using the instructions on their site.
    then I used:
    Qt Code:
    1. LIBS+= -lcurl
    To copy to clipboard, switch view to plain text mode 
    in my .pro file
    then I made sure that libcurl4, libeay32.dll, and libssl32.dll were in my release directory.
    then, in the file where you have code that uses curl you use:
    Qt Code:
    1. #include <curl.h>
    To copy to clipboard, switch view to plain text mode 
    at the top so it knows what to do, and from there, you write code using curl's commands.

    One thing I recommend, is to make a separate worker thread to handle the curl commands and send signals to the main gui thread as to what it's doing. This way your gui won't become sluggish while waiting on curl to do something, and you can make nifty things like a progress bar for your curl task, or allow your user to do something else while curl is working.

    Also, curl has a static callback function which pulls in the whole chunk of data that comes in. If you are looking to parse out specific data from the page, one thing you can do is make a custom callback function that looks for the piece of data you want on the fly and then curl will only return exactly what you want, rather than making you parse the whole page later.

  11. #11
    Join Date
    Oct 2008
    Location
    Europe
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: using libcurl in QT with Mingw in Windows

    First, thank you for replying !

    What does installing libcurl mean? I downloaded the curl-7.19-devel-mingw package and copyed from that to my project directory.

    I get the error:


    c:/Documents and Settings/Administrator/Desktop/bob/hello.cpp:19: undefined reference to `_imp__curl_easy_init'
    c:/Documents and Settings/Administrator/Desktop/bob/hello.cpp:21: undefined reference to `_imp__curl_easy_setopt'
    c:/Documents and Settings/Administrator/Desktop/bob/hello.cpp:22: undefined reference to `_imp__curl_easy_perform'
    c:/Documents and Settings/Administrator/Desktop/bob/hello.cpp:25: undefined reference to `_imp__curl_easy_cleanup'
    collect2: ld returned 1 exit status
    mingw32-make[1]: *** [debug\bob.exe] Error 1


    (i have put LIBS += -L"C:\Documents and Settings\Administrator\Desktop\curl\lib" -lcurl in my .pro file and include curl.h in my .cpp file. I also copied libcurl.dll and libeay32.dll into the release folder)
    I feel i am missing something but.... dunno what.

    later edit: i got it working with -lcurldll in .pro and with the .dlls in debug folder. but id still like to get it working the "other" way if possible.
    Last edited by georgep; 23rd October 2008 at 03:25.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using libcurl in QT with Mingw in Windows

    Quote Originally Posted by georgep View Post
    I downloaded the curl-7.19-devel-mingw package and copyed from that to my project directory.
    This should be enough.

    Quote Originally Posted by georgep View Post
    c:/Documents and Settings/Administrator/Desktop/bob/hello.cpp:19: undefined reference to `_imp__curl_easy_init'
    It looks like there are some symbols missing. That "_imp" prefix suggests that you should use import library. Currently you link against libcurl.a, which is quite big, so it might be a static library. Try linking against libcurldll.a (-lcurldll).

  13. The following user says thank you to jacek for this useful post:

    georgep (23rd October 2008)

  14. #13
    Join Date
    Oct 2008
    Location
    Europe
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: using libcurl in QT with Mingw in Windows

    Heh, i wished I have seen your reply earlyer (-lcurldll)
    If linking -lcurl i will now get a LOT of errors about unknown symbols that appear related to ssl
    how do I link with openssl ?

    ps: how could I say print the contents of a curl reply (a page) in a QLabel (or something like that, any idea?)

  15. #14
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Thanks
    48
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using libcurl in QT with Mingw in Windows

    You might want to take a look at http://curl.haxx.se/docs/libs.html to see what dependencies cURL has.

    In order to use output from curl to something useful such as a QString:
    Qt Code:
    1. QString stuffFromcURL;
    2.  
    3. struct MemoryStruct chunk;
    4. chunk.memory=NULL;
    5. chunk.size = 0;
    6. //.... setting options and other stuff
    7. curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
    8. //.... setting more optons
    9. //exec curl
    10. curl_easy_perform(curl_handle);
    11. stuffFromcURL = QString::fromUtf8 (chunk.memory);
    To copy to clipboard, switch view to plain text mode 

  16. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using libcurl in QT with Mingw in Windows

    Quote Originally Posted by georgep View Post
    how do I link with openssl ?
    The same way as you link with curl (-lssl), but you need to get OpenSSL libraries first.

  17. #16
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: using libcurl in QT with Mingw in Windows

    on pro file ....

    Qt Code:
    1. win32 {
    2. HEADERS += oswin32.h
    3. LIBS += C:/msys/1.0/bin/lib/libz.a
    4. LIBS += C:/msys/1.0/bin/lib/libcurl.dll.a
    5. LIBS += C:/msys/1.0/bin/lib/libcurl.a
    6. LIBS += ../all_os_lib/libexslt.a
    7. LIBS += ../all_os_lib/libxml2.a
    8. LIBS += ../all_os_lib/libxslt.a
    9.  
    10. RC_FILE = win.rc
    11. INCLUDEPATH += C:\MinGW\include C:\msys\1.0\include C:\msys\1.0\home\xml\include
    12. DEPENDPATH += include
    13. DESTDIR = ../installer
    14. }
    To copy to clipboard, switch view to plain text mode 
    i build curl on msys from mingw
    From my first qt project 2 Year a go
    http://sourceforge.net/project/scree...roup_id=167757
    https://qtexcel-xslt.svn.sourceforge...l-xslt/qexcel/

    Get remote file by curl i easy to write , whitout signal or other ..

    search on code:
    https://qtexcel-xslt.svn.sourceforge...rc/_config.cpp
    /* Warning get local file contents or remote file contents by curl */
    QString Config::file_get_contents(QString fullFileName)

  18. #17
    Join Date
    Oct 2008
    Location
    Europe
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Red face Re: using libcurl in QT with Mingw in Windows

    in my .pro file i have

    LIBS += -L"C:\Documents and Settings\Administrator\Desktop\bob\lib" -lcurl -lssl

    and when i make i get thousands of errors like:

    C:\Documents and Settings\Administrator.BOB\Desktop\bob\lib/libssl.a(t1_enc.o):t1_enc.c.text+0x1181): undefined reference to `HMAC_CTX_cleanup'

    I am guessing that it needs hmac.h (and all the other headers from the openssl directory).
    How do I #include ALL those ?

    Thank you very much for your replyes!

  19. #18
    Join Date
    Jan 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using libcurl in QT with Mingw in Windows

    in my .pro file i just used
    Qt Code:
    1. LIBS += -llibcurl
    To copy to clipboard, switch view to plain text mode 
    rather than
    Qt Code:
    1. LIBS += -lcurl
    To copy to clipboard, switch view to plain text mode 
    and BINGO! all compiles and works without errors

  20. #19
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: using libcurl in QT with Mingw in Windows

    Congratulations. Please do not reawaken 6 year old threads after 3 years of dormancy to add nothing of value.

Similar Threads

  1. A Guide to Install MinGW, Qt4 and Eclipse Integration on Windows XP
    By shiyutang in forum Installation and Deployment
    Replies: 10
    Last Post: 5th August 2009, 04:03
  2. Qt + boost + MinGW on Windows
    By akos.maroy in forum Newbie
    Replies: 3
    Last Post: 12th June 2008, 14:53
  3. Mingw very slow on windows
    By elsheikhmh in forum Installation and Deployment
    Replies: 7
    Last Post: 30th May 2007, 17:19
  4. How do I use MinGW Compiler in Windows
    By Walsi in forum General Discussion
    Replies: 3
    Last Post: 11th May 2007, 08:50
  5. qt and mingw can not run on windows 98?
    By evewei in forum Installation and Deployment
    Replies: 4
    Last Post: 26th June 2006, 09:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.