PDA

View Full Version : using libcurl in QT with Mingw in Windows



ct
12th February 2006, 14:51
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 ?

jacek
12th February 2006, 15:45
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?

ct
14th February 2006, 17:14
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

jacek
14th February 2006, 17:28
Try:
LIBS += -L<path to a directory with libcurl.a> -lcurl

ct
14th February 2006, 19:10
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.

jacek
14th February 2006, 19:20
I already have the path in the $PATH of the system...
PATH is for binaries, not libraries.


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

georgep
19th October 2008, 19:04
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

georgep
22nd October 2008, 15:48
Please, anyone ?

jacek
22nd October 2008, 20:31
Do you have libcurl installed?

tpf80
22nd October 2008, 20:36
for starters,
I compiled libcurl with SSL using the instructions on their site.
then I used:


LIBS+= -lcurl

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:


#include <curl.h>

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.

georgep
23rd October 2008, 01:05
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.

jacek
23rd October 2008, 01:31
I downloaded the curl-7.19-devel-mingw package and copyed from that to my project directory.
This should be enough.


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).

georgep
23rd October 2008, 03:29
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?)

tpf80
23rd October 2008, 03:59
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:


QString stuffFromcURL;

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);

jacek
23rd October 2008, 19:31
how do I link with openssl ?
The same way as you link with curl (-lssl), but you need to get OpenSSL libraries first.

patrik08
24th October 2008, 08:40
on pro file ....




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/screenshots.php?group_id=167757
https://qtexcel-xslt.svn.sourceforge.net/svnroot/qtexcel-xslt/qexcel/

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

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

georgep
24th October 2008, 12:13
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!

Spider_xp
22nd January 2012, 17:03
in my .pro file i just used

LIBS += -llibcurl
rather than

LIBS += -lcurl
and BINGO! all compiles and works without errors :)

ChrisW67
23rd January 2012, 01:41
Congratulations. Please do not reawaken 6 year old threads after 3 years of dormancy to add nothing of value.