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 ?
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?
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
Re: using libcurl in QT with Mingw in Windows
Try:
Code:
LIBS += -L<path to a directory with libcurl.a> -lcurl
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.
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>.
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
Re: using libcurl in QT with Mingw in Windows
Re: using libcurl in QT with Mingw in Windows
Do you have libcurl installed?
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:
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:
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.
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.
Re: using libcurl in QT with Mingw in Windows
Quote:
Originally Posted by
georgep
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
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).
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?)
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:
Code:
struct MemoryStruct chunk;
chunk.memory=NULL;
chunk.size = 0;
//.... setting options and other stuff
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
//.... setting more optons
//exec curl
curl_easy_perform(curl_handle);
stuffFromcURL
= QString::fromUtf8 (chunk.
memory);
Re: using libcurl in QT with Mingw in Windows
Quote:
Originally Posted by
georgep
how do I link with openssl ?
The same way as you link with curl (-lssl), but you need to get OpenSSL libraries first.
Re: using libcurl in QT with Mingw in Windows
on pro file ....
Code:
win32 {
HEADERS += oswin32.h
LIBS += C:/msys/1.0/bin/lib/libz.a
LIBS += C:/msys/1.0/bin/lib/libcurl.dll.a
LIBS += C:/msys/1.0/bin/lib/libcurl.a
LIBS += ../all_os_lib/libexslt.a
LIBS += ../all_os_lib/libxml2.a
LIBS += ../all_os_lib/libxslt.a
RC_FILE = win.rc
INCLUDEPATH += C:\MinGW\include C:\msys\1.0\include C:\msys\1.0\home\xml\include
DEPENDPATH += include
DESTDIR = ../installer
}
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)
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!
Re: using libcurl in QT with Mingw in Windows
in my .pro file i just used
rather than
and BINGO! all compiles and works without errors :)
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.