5

I am trying to link libCurl in QT to a C++ program on Windows 7 x64, but when I try to link libcurldll.a, I get a huge list of errors. I have tried compiling a similar function with GCC g++ -LC:\MinGW\lib -lcurldll which compiles without errors. I am using the below code in QT and GCC.

void MainWindow::on_pushButton_2_clicked()
{
    CURL *curl;
    curl = curl_easy_init();
    curl_easy_setopt(curl, CURLOPT_URL, "http://google.com");
    curl_easy_perform(curl);
    curl_easy_cleanup(curl);
}

QT gives me a huge list of errors that I have pasted here. Some of the key errors are tlsthrd.c:-1: error: undefined reference to 'EnterCriticalSection@4' I am using LIBS += -LC:\MinGW\lib -lcurldll in my .pro file to link the project to the curl library. Any idea as to why this is happening? Cheers.

Edit: After a deeper look, it appears as if libmingw32.a is having some issues providing references to functions used for multi-threading. Should I try and replace the library file? If so, why is GCC compiling correctly with the same library file but QT is not?

user99545
  • 1,173
  • 3
  • 16
  • 32
  • 1
    EnterCriticalSection is defined in Kernel32.lib. Maybe you are not including the needed library? – Steve C Jan 22 '12 at 23:54
  • `-lcurl` does not work because I am on Windows. That only works for the Unix libraries. I tried linking the `Kernel32.lib` but even more errors are produced. – user99545 Jan 23 '12 at 00:07

2 Answers2

2

Adding win32:LIBS += c:\MinGW\lib\libcurldll.a to the .pro file did the trick.

user99545
  • 1,173
  • 3
  • 16
  • 32
1

Blarp. Don't use lib curl, Qt has QNetworkAccessManager already which elegantly handles requests and responses using thread-safe Qt signals. Everything you need is there already.

synthesizerpatel
  • 27,321
  • 5
  • 74
  • 91
  • I find libCurl is a better fit for me because I use it with all of my programs. For me to have to learn another library for QT projects only seems impractical. I will take a look at QNetworkAccessmanager though. – user99545 Jan 24 '12 at 13:41
  • If you use lib curl the way you're showing in the example, the entire UI will block while lib curl goes off to do its thing. Which, if you're comfortable with.. by all means. But QNetworkAccessManager is pretty awesome just the same. :D – synthesizerpatel Jan 24 '12 at 13:44
  • Yeah, I discovered that. My plan was to open a thread, perform curl function and then join back. I am assuming that the QNetworkAccessManager does something similar. – user99545 Jan 25 '12 at 00:13
  • In my experience, libcurl is more stable and simply than Qt QNetworkAccessManager. If you have a lot of connections in your app QNetworkAccessManager makes some magic, and could be the cause of app crash. It's because all of your connections go via QNetworkAccessManager singleton. – sherilyn Feb 07 '14 at 15:34