Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Qt - Just can't get LibCurl to install no matter what I try! Need FTP
Forum Updated to NodeBB v4.3 + New Features

Qt - Just can't get LibCurl to install no matter what I try! Need FTP

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
16 Posts 4 Posters 2.7k Views 1 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.
  • S Saminvent

    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 function qMain(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

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #7

    @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.

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • S starkm42

      @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 ?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #8

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      1
      • jsulmJ jsulm

        @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.

        S Offline
        S Offline
        starkm42
        wrote on last edited by
        #9

        @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

        SGaistS 1 Reply Last reply
        1
        • S Offline
          S Offline
          Saminvent
          wrote on last edited by
          #10

          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.0

          SOURCES +=
          main.cpp
          mainwindow.cpp

          HEADERS +=
          mainwindow.h

          FORMS +=
          mainwindow.ui

          /# Default rules for deployment.
          qnx: target.path = /tmp/$${TARGET}/bin
          else: unix:!android: target.path = /opt/$${TARGET}/bin
          !isEmpty(target.path): INSTALLS += target

          win32: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.dll

          INCLUDEPATH += C:/msys64/ucrt64/include
          DEPENDPATH += C:/msys64/ucrt64/include

          SGaistS 1 Reply Last reply
          0
          • S Saminvent

            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.0

            SOURCES +=
            main.cpp
            mainwindow.cpp

            HEADERS +=
            mainwindow.h

            FORMS +=
            mainwindow.ui

            /# Default rules for deployment.
            qnx: target.path = /tmp/$${TARGET}/bin
            else: unix:!android: target.path = /opt/$${TARGET}/bin
            !isEmpty(target.path): INSTALLS += target

            win32: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.dll

            INCLUDEPATH += C:/msys64/ucrt64/include
            DEPENDPATH += C:/msys64/ucrt64/include

            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #11

            @Saminvent You don't link against .dll these are runtime libraries. And usually, the lib part is dropped so it should be -lcurl.

            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
            • S starkm42

              @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

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #12

              @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 drop moc 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.

              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
              • S Offline
                S Offline
                Saminvent
                wrote on last edited by
                #13

                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?

                S 1 Reply Last reply
                0
                • S Saminvent

                  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?

                  S Offline
                  S Offline
                  Saminvent
                  wrote on last edited by
                  #14

                  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.

                  SGaistS 1 Reply Last reply
                  0
                  • S Saminvent

                    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.

                    SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #15

                    @Saminvent what if you include curl before all Qt headers ?

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

                    S 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      @Saminvent what if you include curl before all Qt headers ?

                      S Offline
                      S Offline
                      Saminvent
                      wrote on last edited by
                      #16

                      @SGaist Will give it a try and report back. Cheers

                      1 Reply Last reply
                      0

                      • Login

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