Qt - Just can't get LibCurl to install no matter what I try! Need FTP
-
Hi all, my first post here.
I've spend the past 3 days trying everything I can think of, both with Qmake and Cmake, to get LibCurl installed in a new Qt 6 application. Ideally I'd like to use Cmake as Qmake is on the way out.
Backing up a bit, all I'm trying to achieve at the moment is to create a really simple application that can send and receive files over FTP, however Qt6 discontinued support for FTP in Qt Network.
I would even, at this point, accept a way of using an HTTP API that can communicate with Qt on one end and translate to FTP on the other, but I've not found any APIs that you can actually host yourself on a web server say.
Although is customary to include one's current state of non-working code, if someone else either has experience with LibCurl use in Qt or could potentially try installing using proper practices on their computer, that might be quicker than trying to unpick what I might have done wrong. Online it seems that lots of people (more experienced than myself) have attempted and ran into issues installing LibCurl when it seems like it should be straightforward given its extensive use.
I was using the Mingw64 binaries from LibCurl: libcurl-8.4.0-2-vs16-x64.zip .
At the moment I'm trying to use msys2 to see if that may be an option but it complicates things a bit.
Would appreciate any advice or example code. Many thanks, Sam
-
@Saminvent "Just can't get LibCurl to install no matter what I try!" - this does not tell much. What problems do you have exactly?
-
@jsulm I get errors that the various functions have not been declared. The only header file that should be needed to add into the C or header files is curl.h and this gets properly found, and navigates to the correct other header files if I use find references to symbol or follow symbol under curser. I've tried a number of different things in .pro file (Qmake) and cmakelists.txt to try to properly link the libcurl_a.lib file. include bin and lib folders are in the project directory and path to the files has been set correctly. For Qmake I used the "add libraries -> external libraries ->static libraries and picked the file using the file browser.
Errors include:
error: Unknown type name 'CURL'
error: Use of undeclared identifier 'curl_easy_init'
error: Unknown type name 'CURLcode'
error: Use of undeclared identifier 'CURLOPT_URL'
error: Use of undeclared identifier 'CURLOPT_FOLLOWLOCATION'
error: Use of undeclared identifier 'CURLE_OK' -
Hi and welcome to devnet,
Can you show a minimal
main.cpp
that uses curl and triggers this issue ?That would serve as a starting point to debug your issue.
In any case, the errors you are showing seems to indicate that you did not include the curl header file where you use these symbols.
-
Hi,
Okay so I may have made some progress. I have installed MSYS2 and through that libcurl(mingw-w64-x86_64-curl) and its dependencies as well as ucrt mingw gcc, 64-bit (mingw-w64-ucrt-x86_64-toolchain). I've verified from the terminal that both are working.
I have created a new kit in Qt and assigned the new MinGW g++.exe from the ucrt64/bin folder . Don't know whether it's strictly necessary to do it this way or whether I could use the original and just use the libcurl library from that folder. I've added C:/msys264/ucrt64/bin to path in environmental variable for this kit in Qt.
Here's an example main.cpp which brings these errors:
____________________________________________________
main.cpp
____________________________________________________
#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
#include "C:/msys64/ucrt64/include/curl/curl.h"int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
qDebug() << "qDebug: Application Started";
CURL *curl = curl_easy_init();
if (curl)
{
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL,"https://example.com");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
res = curl_easy_perform(curl);
if (res != CURLE_OK)
{
qDebug() << "transfer fail: %s\n",curl_easy_strerror(res);
}
curl_easy_cleanup(curl);
}return a.exec();
}
____________________________________________________Compiler Output
____________________________________________________
:-1: error: debug/main.o: in functionqMain(int, char**)': pathtofolderredacted\FTPtest4\FTPtest4\main.cpp:13: error: undefined reference to
__imp_curl_easy_init'
:-1: error: pathtofolderredacted\FTPtest4\build-FTPtest4-Desktop_Qt_6_6_0_Msys2_MinGW_64_bit-Debug/../FTPtest4/main.cpp:17: undefined reference to__imp_curl_easy_setopt' :-1: error: pathtofolderredacted\FTPtest4\build-FTPtest4-Desktop_Qt_6_6_0_Msys2_MinGW_64_bit-Debug/../FTPtest4/main.cpp:18: undefined reference to
__imp_curl_easy_setopt'
:-1: error: pathtofolderredacted\FTPtest4\build-FTPtest4-Desktop_Qt_6_6_0_Msys2_MinGW_64_bit-Debug/../FTPtest4/main.cpp:19: undefined reference to__imp_curl_easy_perform' :-1: error: pathtofolderredacted\FTPtest4\build-FTPtest4-Desktop_Qt_6_6_0_Msys2_MinGW_64_bit-Debug/../FTPtest4/main.cpp:22: undefined reference to
__imp_curl_easy_strerror'
:-1: error: pathtofolderredacted\FTPtest4\build-FTPtest4-Desktop_Qt_6_6_0_Msys2_MinGW_64_bit-Debug/../FTPtest4/main.cpp:24: undefined reference to `__imp_curl_easy_cleanup'
:-1: error: collect2.exe: error: ld returned 1 exit status
:-1: error: [Makefile.Debug:72: debug/FTPtest4.exe] Error 1 -
@Saminvent i will just add few observations here based on my experience using third party libraries in Qt
if you are using QMake its very straightforward to add new library, follow this guide :https://doc.qt.io/qtcreator/creator-project-qmake-libraries.html, provide path to you headers i.e. your include files, your compiled archive file i.e libcurl.a etc and you will be able to use libcurl just with.
#include<curl.h>
absolute path would not be required.
ps: prerequisite to above step either you have to build libcurl on windows using mingw or get it using pacman, devel version of libraries.
to further add,
@Saminvent said in Qt - Just can't get LibCurl to install no matter what I try! Need FTP:
:-1: error: debug/main.o: in function qMain(int, char**)': pathtofolderredacted\FTPtest4\FTPtest4\main.cpp:13: error: undefined reference to __imp_curl_easy_init'
this says you have specified your forward declarations using the absolute path to your header files, but linker is not able to find definitions for your functions. which is usually done with -L/path/to/compiled/archive/file -llib<library> name with normal compilation. with above guide qt will automatically do this for you once configured to do so i.e. by editing your Qmake file.
to do the same using CMake is something i still have yet to figure out. but i bet its trivial.
ps: i don't think you can use compiler other that what Qt ships with, because some parts of Qt code are not even c++ language compliant. qt first translates your source code to c++ compatible i.e moc_source_code.cpp which i believe can be compiled using any g++ compiler. can anybody correct me if this statement is true ? -
@Saminvent It looks like you're not linking Curl lib or Curl lib was build using different compiler than the one you're using. Please show your pro file.
-
@starkm42 said in Qt - Just can't get LibCurl to install no matter what I try! Need FTP:
because some parts of Qt code are not even c++ language compliant. qt first translates your source code to c++ compatible i.e moc_source_code.cpp
This is not correct. Qt ships MinGW which is simply Windows port of GCC. You can also use Qt with unmodified Microsoft compiler. Moc simply generates code (for signals for example), signals/slots keywords are just empty macros.
-
@jsulm yeah, i should have worded it differently. compilers are same as you would get without Qt creator but there is a pre-step before actual code gets compiled by Qt creator itself i.e. moc ?. i will redact my statement. thanks for the insight
-
My .pro file is as follows.
I get an extra error if I don't comment out the debug dll line auto added by the add library wizard. Maybe something to do with separate debug dlls no longer being needed, anyway I don't think it's what's causing my problems.QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
/# You can make your code fail to compile if it uses deprecated APIs.
/# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0SOURCES +=
main.cpp
mainwindow.cppHEADERS +=
mainwindow.hFORMS +=
mainwindow.ui/# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += targetwin32:CONFIG(release, debug|release): LIBS += -LC:/msys64/ucrt64/lib/ -llibcurl.dll
#else:win32:CONFIG(debug, debug|release): LIBS += -LC:/msys64/ucrt64/lib/ -llibcurl.dlld
#else:unix: LIBS += -LC:/msys64/ucrt64/lib/ -llibcurl.dllINCLUDEPATH += C:/msys64/ucrt64/include
DEPENDPATH += C:/msys64/ucrt64/include -
@Saminvent You don't link against
.dll
these are runtime libraries. And usually, the lib part is dropped so it should be-lcurl
. -
@starkm42
moc
is really only involved if you are writing a QObject based class which used the Q_OBJECT macro and as @jsulm said it's a code generator. You can even dropmoc
if using the verdigris project. Qt is a C++ framework and it follows the rules and the standard. If it were not, you would not be able to compile it. -
Hiya, okay so I tried various things (including changing the .pro line to LIBS += -LC:/msys64/ucrt64/lib/ -lcurl as before I was using the win32:config which I think broke things, maybe meant to be win64?) and that helped a bit, then I was having issues with qDebug() crashing the application (and this is still an issue at the time of writing this). I then also edited all the header files to use absolute paths just in case once into curl.h other linked header files couldn't find each other with relative paths. This is obviously not a solution for deployment but a good debugging tool.
Anyway, now it just seems to build and work correctly, without qDebug().
What's strange is that in a brand new application this was working, but adding the curl library seems to have broken it.Current state of things - curl successfully pulls data off a test website and I'll now try to implement ftp with it. The issue I have now is that if I use qDebug() the application exits with an error saying it crashed.
Any thoughts on the cause of this?
-
Have tried on fresh applications and linking the library doesn't break qDebug() but as soon as I add my #include for curl.h, it does break. With normal run in debug mode it just crashes, but if I run with debugger, I get the following errors, but I am able to get qDebug() outputs displaying in the Application Output window.
Invalid address specified to RtlFreeHeap( 0000024C02A30000, 0000024C04401A80 )
MainWindow Opened
clientcore\windows\advcore\ctf\uim\tim.cpp(800)\MSCTF.dll!00007FFD8BEF62B9: (caller: 00007FFD8BEF6EEC) LogHr(1) tid(319c) 8007029C An assertion failure has occurred.
clientcore\windows\advcore\ctf\uim\tim.cpp(800)\MSCTF.dll!00007FFD8BEF62B9: (caller: 00007FFD8BEF6EEC) LogHr(2) tid(319c) 8007029C An assertion failure has occurred.
mincore\com\oleaut32\dispatch\ups.cpp(2126)\OLEAUT32.dll!00007FFD8A60470C: (caller: 00007FFD8A6049FA) ReturnHr(1) tid(319c) 8002801D Library not registered. -
@Saminvent what if you include curl before all Qt headers ?