PDA

View Full Version : Curl in QT Creator



januszmk
18th July 2011, 22:49
Hello!
I wanted to use curl lib in my program but I have problem with this lib in qt creator.
In .pro file i have something like that:

INCLUDEPATH += "D:/Qt/curl-7.21.6-devel-mingw32/include"
win32:LIBS += -L"D:/Qtcurl-7.21.7-ssl-sspi-zlib-static-bin-w32" -lcurl
And in header file I am including curl/curl.h. QT Creator see the functions for curl, but when I want to build, I get:

release/downloader.o:downloader.cpp:(.text+0x1b1): undefined reference to `_imp__curl_easy_init'
release/downloader.o:downloader.cpp:(.text+0x1cd): undefined reference to `_imp__curl_easy_setopt'
collect2: ld returned 1 exit status
I found couple informations how to install curl in windows and use in qt creator but i always get that error. I tried to link .dll files and .a files, effect is the same. Of course I have declared appropriate:

CURL *curl;
curl = curl_easy_init();
etc
I tried even install curl by mingw32-make, but even if i had installed libssl and zlib, I get errors about missing zlib, ssl and something else.
I want to use curl, becouse in qnetworkaccessmeneger when i post into a site, then i get a message then i'm not using a cookie, even I setup them.
I would be grateful if you could help me.
Sory for my bad English
Janusz

mcosta
19th July 2011, 08:17
Try to include cURL header with extern "C"



extern "C" {
#include <curl/curl.h>
}

januszmk
19th July 2011, 12:00
This didn't help,

mingw32-make[1]: Leaving directory `D:/Qt/qtcreator-2.2.1/untitled4-build-desktop'
release/downloader.o:downloader.cpp:(.text+0x1b1): undefined reference to `_imp__curl_easy_init'
release/downloader.o:downloader.cpp:(.text+0x1cd): undefined reference to `_imp__curl_easy_setopt'
collect2: ld returned 1 exit status

mvuori
19th July 2011, 12:08
I don't know anything about Curl, but a quick Google search with the error message (you must have done that too...) gives the impression that you need to define CURL_STATICLIB in your project

(probably in .pro: DEFINES += CURL_STATICLIB)

januszmk
19th July 2011, 12:33
Like I said, I found some information about this and i tried already add defines curl_staticlib but it didn't help. I thought then someone have problem like me and know how to resolve, but if no one know what to do with that, I have to find other solution without curl.
Thanks

mcosta
19th July 2011, 13:22
have you built curl with the same compiler you're using for build your application?

Post your PRO file

januszmk
19th July 2011, 15:12
#-------------------------------------------------
#
# Project created by QtCreator 2011-07-16T13:56:53
#
#-------------------------------------------------

QT += core gui
QT += network


TARGET = untitled4
TEMPLATE = app


SOURCES += main.cpp\
project.cpp

HEADERS += project.h

FORMS += project.ui

INCLUDEPATH += "D:/Qt/curl-7.21.6-devel-mingw32/include"
win32:LIBS += -L"D:/Qtcurl-7.21.7-ssl-sspi-zlib-static-bin-w32" -lcurl
DEFINES += CURL_STATICLIB

I didn't build, just download already builded from curl site for windows/mingw32. When I tried to build from source with ssl and zlib, then I get error, "can't find -lz -lssl" or something like that, even if i already installed this lib.

mcosta
19th July 2011, 16:23
Try defining CURL_STATICLIB BEFORE INCLUDEPATH and LIBS

januszmk
19th July 2011, 18:45
I found the solution. I define CURL_STATICLIB in my header file, before included curl.h.
Thanks

gregowbr
25th August 2011, 12:09
I'm having the same problem since you found the solution, please help me out.

This is my code:


#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
CURL *curl;
CURLcode res;

curl = curl_easy_init();
/*
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
res = curl_easy_perform(curl);


curl_easy_cleanup(curl);
}
*/
return 0;
}

it returns the same error you were having: undefined reference to `_imp__curl_easy_init'

by the way, I didn't compile the library (if it is necessary) I just downloaded and moved the curl library (that contains the curl.h, curlbuild.h) what do I need to do to make it work ? do I need to compile if yes, where do I do that, Its been days I've been looking for, But I don't understand what to do. I see something to use the mingw32-make mingw32 in the curl library but I don't get it fully. =/ please help me out, and also that CURL_STATICLIB what do I define in it? is it something in the code like this: #define CURL_STATICLIB

By the way I'm using CodeBlocks that comes with the Mingw. I would be very glad if you could help me, step-to-step.

ChrisW67
25th August 2011, 23:14
I'm having the same problem since you found the solution, please help me out.
...
By the way I'm using CodeBlocks that comes with the Mingw. I would be very glad if you could help me, step-to-step.

So, you have a libCurl example program that uses the non-Qt Curl library. You are writing it using the non-Qt Code Blocks IDE and MingW. Why ask the question in a Qt forum? :confused:

If you downloaded the libCurl source then you will need to build it. The instructions are in the source. Have you built it?

If you have built it or downloaded a built version then either the compiler is not finding the built library, or you need to follow the preceding post, which tells you tell you exactly how to address this problem.

that CURL_STATICLIB what do I define in it? is it something in the code like this: #define CURL_STATICLIB
Did you try it before you posted?