Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Cannot compile



  • Hello, I started a small project. I need to use an external library (.a).

    .pro

    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = OgameBot
    TEMPLATE = app
    
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which has been marked as deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #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
    
    
    
    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../libRequests/release/ -lRequests
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../libRequests/debug/ -lRequests
    else:unix: LIBS += -L$$PWD/../libRequests/ -lRequests
    
    INCLUDEPATH += $$PWD/../libRequests
    DEPENDPATH += $$PWD/../libRequests
    
    win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../libRequests/release/libRequests.a
    else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../libRequests/debug/libRequests.a
    else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../libRequests/release/Requests.lib
    else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../libRequests/debug/Requests.lib
    else:unix: PRE_TARGETDEPS += $$PWD/../libRequests/libRequests.a
    

    main.cpp

    #include <QApplication>
    
    #include "mainwindow.h"
    #include "Request.h"
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
    
        HTTP::Request request;
    
        return a.exec();
    }
    

    I just call HTTP::Request which is in the external library.

    Here are the errors in the compilation:

    /Library/Developer/CommandLineTools/usr/bin/clang++ -stdlib=libc++ -headerpad_max_install_names  -arch x86_64 -Wl,-syslibroot,/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -mmacosx-version-min=10.10 -Wl,-rpath,@executable_path/Frameworks -Wl,-rpath,/Users/jordanbarbe/Qt/5.10.1/clang_64/lib -o OgameBot.app/Contents/MacOS/OgameBot main.o mainwindow.o moc_mainwindow.o   -F/Users/jordanbarbe/Qt/5.10.1/clang_64/lib -L/Users/jordanbarbe/go-workspace/Project/OgameBot/../libRequests/ -lRequests -framework QtWidgets -framework QtGui -framework QtCore -framework DiskArbitration -framework IOKit -framework OpenGL -framework AGL 
    ld: warning: object file (/Users/jordanbarbe/go-workspace/Project/libRequests/libRequests.a(Request.o)) was built for newer OSX version (10.13) than being linked (10.10)
    ld: warning: object file (/Users/jordanbarbe/go-workspace/Project/libRequests/libRequests.a(Headers.o)) was built for newer OSX version (10.13) than being linked (10.10)
    ld: warning: object file (/Users/jordanbarbe/go-workspace/Project/libRequests/libRequests.a(Response.o)) was built for newer OSX version (10.13) than being linked (10.10)
    Undefined symbols for architecture x86_64:
      "_curl_easy_cleanup", referenced from:
          HTTP::Request::~Request() in libRequests.a(Request.o)
          HTTP::Request::~Request() in libRequests.a(Request.o)
      "_curl_easy_getinfo", referenced from:
          HTTP::Request::perform(HTTP::Response&) in libRequests.a(Request.o)
      "_curl_easy_init", referenced from:
          HTTP::Request::Request() in libRequests.a(Request.o)
          HTTP::Request::Request() in libRequests.a(Request.o)
      "_curl_easy_perform", referenced from:
          HTTP::Request::perform(HTTP::Response&) in libRequests.a(Request.o)
      "_curl_easy_reset", referenced from:
          HTTP::Request::Request() in libRequests.a(Request.o)
          HTTP::Request::curlReset() in libRequests.a(Request.o)
          HTTP::Request::Request() in libRequests.a(Request.o)
          HTTP::Request::get(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libRequests.a(Request.o)
          HTTP::Request::get(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, HTTP::Headers const&) in libRequests.a(Request.o)
          HTTP::Request::post(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libRequests.a(Request.o)
          HTTP::Request::post(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, HTTP::Headers const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libRequests.a(Request.o)
          ...
      "_curl_easy_setopt", referenced from:
          HTTP::Request::Request() in libRequests.a(Request.o)
          HTTP::Request::curlReset() in libRequests.a(Request.o)
          HTTP::Request::Request() in libRequests.a(Request.o)
          HTTP::Request::get(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libRequests.a(Request.o)
          HTTP::Request::get(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, HTTP::Headers const&) in libRequests.a(Request.o)
          HTTP::Request::post(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libRequests.a(Request.o)
          HTTP::Request::post(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, HTTP::Headers const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libRequests.a(Request.o)
          ...
      "_curl_easy_strerror", referenced from:
          HTTP::Request::perform(HTTP::Response&) in libRequests.a(Request.o)
      "_curl_slist_append", referenced from:
          HTTP::Headers::set(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libRequests.a(Headers.o)
          HTTP::Headers::set(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libRequests.a(Headers.o)
      "_curl_slist_free_all", referenced from:
          HTTP::Headers::~Headers() in libRequests.a(Headers.o)
          HTTP::Headers::clear() in libRequests.a(Headers.o)
          HTTP::Headers::~Headers() in libRequests.a(Headers.o)
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [OgameBot.app/Contents/MacOS/OgameBot] Error 1
    

    here is the library I'm trying to use: lib request

    Thank you for your future answer.

    [Edit ~aha_1980: fixed link]


  • Lifetime Qt Champion

    @El_Professor said in Cannot compile:

    I'm no Mac user, but these lines looks suspicious to me:

    ld: warning: object file (/Users/jordanbarbe/go-workspace/Project/libRequests/libRequests.a(Request.o)) was built for newer OSX version (10.13) than being linked (10.10)
    ld: warning: object file (/Users/jordanbarbe/go-workspace/Project/libRequests/libRequests.a(Headers.o)) was built for newer OSX version (10.13) than being linked (10.10)
    ld: warning: object file (/Users/jordanbarbe/go-workspace/Project/libRequests/libRequests.a(Response.o)) was built for newer OSX version (10.13) than being linked (10.10)

    ld: symbol(s) not found for architecture x86_64

    Did you get the library pre-compiled? From where? Can you build it yourself?



  • Hi, yes I compiled the library well before. I have my request.a file and 3 header files. I added the library via Qt with a right click on the project then "add a new library" .
    So I was looking for the library in my computer in another folder in Qt. I selected external library.

    thanks you


  • Lifetime Qt Champion

    @El_Professor said in Cannot compile:

    Hi, yes I compiled the library well before.

    Hmm, so why does the linker complains:

    ld: warning: object file [..] was built for newer OSX version (10.13) than being linked (10.10)

    Maybe a Mac user can help you more in that regard.



  • I don't know exactly. I only cloned the above mentioned repository. and then made a Make in this repository which directly creates a libRequests.a file for me.


  • Lifetime Qt Champion

    @El_Professor

    It seems that library handles HTTP requests. Any reason you don't use Qt's QNetworkAccessManager?



  • I don't know. I thought we couldn't deal with it?

    thanks you for reply


  • Lifetime Qt Champion

    @El_Professor So what do you want to do exactly?



  • I'm learning. So I try to get a web page for example from a game and then connect to that game via the c++/Qt code.


  • Lifetime Qt Champion

    @El_Professor so why can't you use QNetworkAccessManager?



  • In fact a friend explained to me that he was using this library I thought I would take the same one. I forgot Qt can do it. Thank you for your response. I already started my program with this class. And I can do the same thing with librequest for lib.a.
    sorry for the inconvenience


Log in to reply