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. Importing libraries and including them still gives undefined references
Forum Updated to NodeBB v4.3 + New Features

Importing libraries and including them still gives undefined references

Scheduled Pinned Locked Moved Solved General and Desktop
libraries
6 Posts 4 Posters 1.3k 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.
  • R Offline
    R Offline
    RekTekk249
    wrote on last edited by
    #1

    I'm quite new to c++ and Qt in general, so I might have made some obvious mistake here, but I spent the last couple hours trying to figure that out and still no luck. He're the code in question, from the bit7z library:

    try {
            bit7z::Bit7zLibrary lib( L"7za.dll" );
            bit7z::BitExtractor extractor( lib, bit7z::BitFormat::Zip );
            //Trimming extension
            QString subDirectory = "sub/" +
                    QString::fromStdString(fileName
                               .toStdString().substr(0,
                                           fileName.toStdString().find_last_of(".")));
    
            CreateDirectoryA(subDirectory.toLocal8Bit().data(), nullptr);
            extractor.extract(L"sub/" + fileName.toStdWString(), subDirectory.toStdWString());
    
        }catch (const bit7z::BitException& ex ) {
            qDebug() << ex.what();
        }
    

    Getting undefined references on every instance of bit7z... I know the string manipulation are probably not good, but I'm used to python where everything "" is a string, while here you have char* char[] std::string QString wstring wchar* and such... Every function takes a different type of string and none of theses are compatible...
    The .pro file:

    ...
    ...
    DISTFILES +=
    
    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/bit7z/lib/ -lbit7z64
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/bit7z/lib/ -lbit7z64_d
    else:unix: LIBS += -L$$PWD/bit7z/lib/ -lbit7z64
    
    INCLUDEPATH += $$PWD/bit7z/include
    DEPENDPATH += $$PWD/bit7z/include
    

    What am I missing here? I don't see any error in the IDE until compilation. I've added the library with the "Add library" option when you right click and "external library".

    aha_1980A 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      So what error do you get? Since it's a C++ library - is Qt and the library compiled with the same compiler? You can't mix msvc and mingw here.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • R RekTekk249

        I'm quite new to c++ and Qt in general, so I might have made some obvious mistake here, but I spent the last couple hours trying to figure that out and still no luck. He're the code in question, from the bit7z library:

        try {
                bit7z::Bit7zLibrary lib( L"7za.dll" );
                bit7z::BitExtractor extractor( lib, bit7z::BitFormat::Zip );
                //Trimming extension
                QString subDirectory = "sub/" +
                        QString::fromStdString(fileName
                                   .toStdString().substr(0,
                                               fileName.toStdString().find_last_of(".")));
        
                CreateDirectoryA(subDirectory.toLocal8Bit().data(), nullptr);
                extractor.extract(L"sub/" + fileName.toStdWString(), subDirectory.toStdWString());
        
            }catch (const bit7z::BitException& ex ) {
                qDebug() << ex.what();
            }
        

        Getting undefined references on every instance of bit7z... I know the string manipulation are probably not good, but I'm used to python where everything "" is a string, while here you have char* char[] std::string QString wstring wchar* and such... Every function takes a different type of string and none of theses are compatible...
        The .pro file:

        ...
        ...
        DISTFILES +=
        
        win32:CONFIG(release, debug|release): LIBS += -L$$PWD/bit7z/lib/ -lbit7z64
        else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/bit7z/lib/ -lbit7z64_d
        else:unix: LIBS += -L$$PWD/bit7z/lib/ -lbit7z64
        
        INCLUDEPATH += $$PWD/bit7z/include
        DEPENDPATH += $$PWD/bit7z/include
        

        What am I missing here? I don't see any error in the IDE until compilation. I've added the library with the "Add library" option when you right click and "external library".

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by aha_1980
        #3

        Hi @RekTekk249,

        Just one addition to @Christian-Ehrlicher: Your program needs the same archticture (bitness) as your library, please check that too.

        Regarding the second point: indeed string handling is horrible in C and only partly better in C++; but with QString you have a mighty and locale aware toolbox.

           QString subDirectory = "sub/" +
                    QString::fromStdString(fileName
                               .toStdString().substr(0,
                                           fileName.toStdString().find_last_of(".")));
        

        So this can be done better (uncompiled + untested):

        const QString subDirectory = "sub/" + fileName.mid(0, fileName.lastIndexOf('.'));

        CreateDirectoryA(subDirectory.toLocal8Bit().data(), nullptr);

        Note that is is platform specific (Windows) API and only works for ASCII filenames. A bit better would be:

        CreateDirectoryW(reinterpret_cast<const wchar_t *>(subDirectory.utf16()), nullptr);

        extractor.extract(L"sub/" + fileName.toStdWString(), subDirectory.toStdWString());

        And here it depends on which parameters extract() expects.

        Hope that helps.

        Regards

        Qt has to stay free or it will die.

        1 Reply Last reply
        1
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          To add to @aha_1980 additions, QDir has QDir::mkdir which is cross-platform so you don't have to play with native API for that kind of action.

          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
          • R Offline
            R Offline
            RekTekk249
            wrote on last edited by
            #5

            Yes, thanks for that, I wasn't aware that compilers weren't compatible... The library is open source, I'll just recompile it. Also, I heard of Qt::mkdir, but apparently it's doesn't have good performances, but I got this from a year old SO thread, it might have been better now.. I'll give it a try. I know CreateDirectoryW is a windows api function, but it was the simplest to use, and I had my fileName filtered with regex to be letters/numbers only for other reasons. For the strings, I was totally unaware of the QString.mid() function... I was looking on the docs for sub subs sub_str substring and stuff like that.. Thanks for that, I got it working now! That's the first time I encounter a language with multiple compilers like that... C and its variants seem to be the only one. Honestly though it feels like Qt is it's own language, more than a framework...

            1 Reply Last reply
            1
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @RekTekk249 said in Importing libraries and including them still gives undefined references:

              Also, I heard of Qt::mkdir, but apparently it's doesn't have good performances

              micro-optimization - you call it once... it's just not worth the trouble.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              3

              • Login

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