cURL and Qt Project
-
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
-
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
@ganeshkbhat
The paths looks wrong ?When they are not full as in
c:/vendor/xxx
then often they are relative
../../vendor/xxxxYours 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 ? -
I have my project in
tester/allMyFilesAndFolders
. It also means that my vendor folder is withintester/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.
-
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?
-
This post is deleted!
-
@ganeshkbhat
The paths looks wrong ?When they are not full as in
c:/vendor/xxx
then often they are relative
../../vendor/xxxxYours 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 ?@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);
-
@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);
@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. -
QT += core gui
QT += quickcontrols2greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = APITester
TEMPLATE = appDEFINES += 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.dllINCLUDEPATH += $$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.aErrors are follow (one of them is. Its one of the functions curl exposes) :
undefined reference to _imp__curl_easy_init()'
-
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.
-
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. -
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:
- I added the .lib / .dll.a file with full path (from C:) in .pro
- I added the include full path (from C:) in .pro
- I added the curl.exe and libcurl.exe in the release folders along with other dependency .dlls
Detailed steps:
-
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
orC:\git\QT\APITester\vendor\curl\lib\libcurl.lib
and -
I added the include full path:
C:\git\QT\APITester\vendor\curl\include
-
I added the
curl.exe
andlibcurl.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.
-
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?
-
@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 pointYou 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.
-
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.
-
Ah no. I am using mingw compiler and qtcompiler with mingw