Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. cURL and Qt Project
Forum Updated to NodeBB v4.3 + New Features

cURL and Qt Project

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 4 Posters 15.9k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    ganeshkbhat
    wrote on 12 Mar 2017, 10:23 last edited by A Former User
    #1

    I have created a QT project for a desktop application and I am able to work with it right. However I now need the curl library and need to use it correctly. But the compilations hs problems. The issue is I downloaded the source from https://curl.haxx.se/download.html and using the documentation from http://doc.qt.io/qt-5/third-party-libraries.html . I am importing curl.h in one of my .cpp files like the curl doc says. But I am getting an error cannot find -lcurl

    Here is what I have included in my .pro file

    INCLUDEPATH += vendor/curl/include/curl \

    LIBS += -L"vendor/curl/lib" -lcurl

    M 1 Reply Last reply 12 Mar 2017, 10:56
    0
    • G ganeshkbhat
      12 Mar 2017, 10:23

      I have created a QT project for a desktop application and I am able to work with it right. However I now need the curl library and need to use it correctly. But the compilations hs problems. The issue is I downloaded the source from https://curl.haxx.se/download.html and using the documentation from http://doc.qt.io/qt-5/third-party-libraries.html . I am importing curl.h in one of my .cpp files like the curl doc says. But I am getting an error cannot find -lcurl

      Here is what I have included in my .pro file

      INCLUDEPATH += vendor/curl/include/curl \

      LIBS += -L"vendor/curl/lib" -lcurl

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 12 Mar 2017, 10:56 last edited by mrjj 3 Dec 2017, 11:00
      #2

      @ganeshkbhat
      The paths looks wrong ?

      When they are not full as in
      c:/vendor/xxx
      then often they are relative
      ../../vendor/xxxx

      Yours seems to be neither ?

      Also, its unclear if you build it all your self or you try to use PRECOMPILED dlls ?
      Did you fist build the actual libCurl ?

      G 1 Reply Last reply 12 Mar 2017, 13:54
      0
      • G Offline
        G Offline
        ganeshkbhat
        wrote on 12 Mar 2017, 10:59 last edited by ganeshkbhat 3 Dec 2017, 11:01
        #3

        I have my project in tester/allMyFilesAndFolders . It also means that my vendor folder is within tester/vendor/curl Is that also wrong?

        Second, I have downloaded all the source. Not the built ones so I am able to use that in both windows and linux after compilation. I have not built the libCurl first but I have tried putting the binary in the lib folder and tried but it did not work.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          ganeshkbhat
          wrote on 12 Mar 2017, 11:39 last edited by
          #4

          I remove the -lcurl key and it allowed me to compile but not I have a bunch of errors of undefined related to functions used by curl. eg: undefined reference to 'curl_easy_init()' . Seems like the path issue itself. Any help? I have the source files in the folders and the lib folder has both source .cpp files as well as built binary (which i put for testing purposes only). Any help. Is it wise to compile the curl first and then use the library dll in the project?

          1 Reply Last reply
          0
          • G Offline
            G Offline
            ganeshkbhat
            wrote on 12 Mar 2017, 13:46 last edited by ganeshkbhat 3 Dec 2017, 13:47
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • M mrjj
              12 Mar 2017, 10:56

              @ganeshkbhat
              The paths looks wrong ?

              When they are not full as in
              c:/vendor/xxx
              then often they are relative
              ../../vendor/xxxx

              Yours seems to be neither ?

              Also, its unclear if you build it all your self or you try to use PRECOMPILED dlls ?
              Did you fist build the actual libCurl ?

              G Offline
              G Offline
              ganeshkbhat
              wrote on 12 Mar 2017, 13:54 last edited by
              #6

              @mrjj I have now been able to compile the libcurl.dll.a file into the lib folder and used a library importer to create the library dependency. Now the -lcurl error is gone. But it still gives undefined errors. What declaration have I gone wrong at? Error is >>> :-1: error: undefined reference to _imp__curl_easy_init' and error are there for other curl functions as well.

              This is my import :
              #include <curl/curl.h>

              This is my code within my widget constructor

              CURL *curl;
              CURLcode res;

                curl = curl_easy_init();
                if(curl) {
                    curl_easy_setopt(curl, CURLOPT_URL, "http://google.com");
                    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
                    res = curl_easy_perform(curl);
                    if(res != CURLE_OK){
                        qWarning("curl_easy_perform() failed: \n");
                    }
                  curl_easy_cleanup(curl);
              
              M 1 Reply Last reply 12 Mar 2017, 15:27
              0
              • G ganeshkbhat
                12 Mar 2017, 13:54

                @mrjj I have now been able to compile the libcurl.dll.a file into the lib folder and used a library importer to create the library dependency. Now the -lcurl error is gone. But it still gives undefined errors. What declaration have I gone wrong at? Error is >>> :-1: error: undefined reference to _imp__curl_easy_init' and error are there for other curl functions as well.

                This is my import :
                #include <curl/curl.h>

                This is my code within my widget constructor

                CURL *curl;
                CURLcode res;

                  curl = curl_easy_init();
                  if(curl) {
                      curl_easy_setopt(curl, CURLOPT_URL, "http://google.com");
                      curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
                      res = curl_easy_perform(curl);
                      if(res != CURLE_OK){
                          qWarning("curl_easy_perform() failed: \n");
                      }
                    curl_easy_cleanup(curl);
                
                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 12 Mar 2017, 15:27 last edited by
                #7

                @ganeshkbhat
                Hi
                Try to post the .pro file and the output in Creators compiler output panel
                It stills sounds like its not linking. There must be errors somewhere.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  ganeshkbhat
                  wrote on 12 Mar 2017, 15:33 last edited by ganeshkbhat 3 Dec 2017, 15:39
                  #8

                  QT += core gui
                  QT += quickcontrols2

                  greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

                  TARGET = APITester
                  TEMPLATE = app

                  DEFINES += QT_DEPRECATED_WARNINGS

                  #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000

                  SOURCES += main.cpp
                  mainwindow.cpp
                  apitab.cpp \

                  HEADERS += mainwindow.h
                  apitab.h \

                  FORMS += mainwindow.ui
                  apitab.ui \

                  DISTFILES +=

                  RESOURCES +=

                  INCLUDEPATH +=

                  LIBS +=

                  win32:CONFIG(release, debug|release): LIBS += -L$$PWD/vendor/curl/lib/ -llibcurl.dll
                  else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/vendor/curl/lib/ -llibcurl.dlld
                  else:unix: LIBS += -L$$PWD/vendor/curl/lib/ -llibcurl.dll

                  INCLUDEPATH += $$PWD/vendor/curl/include \

                  DEPENDPATH += $$PWD/vendor/curl/include

                  win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/vendor/curl/lib/libcurl.dll.a
                  else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/vendor/curl/lib/libcurl.dlld.a
                  else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/vendor/curl/lib/libcurl.dll.lib
                  else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/vendor/curl/lib/libcurl.dlld.lib
                  else:unix: PRE_TARGETDEPS += $$PWD/vendor/curl/lib/libcurl.dll.a

                  ==========================

                  The folder structure is :

                  projectfolder/
                  file.cpp (and others)
                  file.h
                  main.cpp
                  vendor/
                  vendor/curl/
                  vendor/curl/include/
                  vendor/curl/include/curl.h (and others)
                  vendor/curl/lib/
                  vendor/curl/lib/libcurl.dll.a

                  Errors are follow (one of them is. Its one of the functions curl exposes) :

                  undefined reference to _imp__curl_easy_init()'

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 12 Mar 2017, 17:10 last edited by
                    #9

                    Hi
                    Sometimes you need to use the .lib file if using visual studio.
                    what compiler ?
                    Also i hope you compiled all of curl yourself.

                    try with
                    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/vendor/curl/lib/ -lcurl.dll
                    ( that is remove the lib start of the name. here.)
                    make release build.

                    Sorry its hard to offer more input without the compiler output :)

                    I think its nearly correct. path seems fine etc.

                    1 Reply Last reply
                    1
                    • G Offline
                      G Offline
                      ganeshkbhat
                      wrote on 12 Mar 2017, 19:43 last edited by
                      #10

                      Hmm.... seems like an issue here. I am actually doing a release build and win32:CONFIG(release, debug|release): LIBS += -L$$PWD/vendor/curl/lib/ -lcurl.dll does not work. I have created a new project with just one file and the curl functions and seems it is still giving the same error.

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 12 Mar 2017, 21:02 last edited by
                        #11

                        Hi and welcome to devnet,

                        You don't link to .dll files.

                        Note that you haven't answered @mrjj'question: which compiler are you using ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        1
                        • G Offline
                          G Offline
                          ganeshkbhat
                          wrote on 13 Mar 2017, 01:17 last edited by
                          #12

                          I was using mingw and cygwin compiler. I sat the whole night figuring out what issue was and found that it was the path "resolution" issue as mrjj pointed out.

                          Here is what resolved my issue for developers who face the issue of External Library not linking correctly to a QT project in windows:

                          1. I added the .lib / .dll.a file with full path (from C:) in .pro
                          2. I added the include full path (from C:) in .pro
                          3. I added the curl.exe and libcurl.exe in the release folders along with other dependency .dlls

                          Detailed steps:

                          1. Instead of the relative path, I gave the actual full path to library file in the .pro file and it resolved my issue. Here are the file paths I added.
                            C:\git\QT\APITester\vendor\curl\lib\libcurl.dll.a or C:\git\QT\APITester\vendor\curl\lib\libcurl.lib and

                          2. I added the include full path: C:\git\QT\APITester\vendor\curl\include

                          3. I added the curl.exe and libcurl.dll in the release folder (main folder) with other dependency .dlls of QT and created a release build.

                          The above steps work as well for debug but you have to have dlld files there for curl there

                          I do not know what config settings are getting messed up for this issue to happen. And most of all such linking issues with third party libraries are not documented well. One of the biggest issues of C++ community and adoption is the project set up documentation and project deployment documentation is not good.

                          This community saved me here. Thanks all for the effort and support. Thanks to @mrjj and @SGaist who spent time to answer my questions.

                          1 Reply Last reply
                          2
                          • T Offline
                            T Offline
                            tham
                            wrote on 13 Mar 2017, 03:06 last edited by
                            #13

                            One of the biggest issues of C++ community and adoption is the project set up documentation and project deployment documentation is not good.

                            I share your pain, but this is not just the problem of c++, recently I found the same issue with those deep learning libraries written by python, the truth is, many developers do not care as long as their libs work on linux.

                            May I ask you why you refuse to use the network modules provided by Qt5?

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              ganeshkbhat
                              wrote on 13 Mar 2017, 03:54 last edited by
                              #14

                              @tham
                              May I ask you why you refuse to use the network modules provided by Qt5?
                              The network modules of QT is good! I can say that looking at the class documentation though I am a beginner with QT. I needed time tracking based results for network requests like this http://i63.tinypic.com/21ls83l.png which is quite cumbersome and may be not possible with the QT network module.

                              @SGaist
                              You can link external .dll files for your point You don't link to .dll files. . I was able to do that for an external library linking with QT using sqlite3.dll and it worked fine. Not sure why you referred that.

                              @tham
                              recently I found the same issue with those deep learning libraries written by python, the truth is, many developers do not care as long as their libs work on linux.
                              True. I found that. But QT is not like that. QT is a commercial product for sale. Thats what makes a product/concept mature and marketable.

                              I definitely believe there needs to be better documentation on minor issues and tweaks for product like QT. Frankly, its one of the best I found for C++ UI Controls and the performance is... good for the features it provides.

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 13 Mar 2017, 08:05 last edited by
                                #15

                                Usually when that works, it's because you have the matching .lib files (in the case of Visual Studio) in the same folder as your .dll files and the linker picks that one up.

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                1
                                • G Offline
                                  G Offline
                                  ganeshkbhat
                                  wrote on 13 Mar 2017, 17:58 last edited by
                                  #16

                                  Ah no. I am using mingw compiler and qtcompiler with mingw

                                  1 Reply Last reply
                                  0

                                  8/16

                                  12 Mar 2017, 15:33

                                  • Login

                                  • Login or register to search.
                                  8 out of 16
                                  • First post
                                    8/16
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved