Search code examples
c++qt5visual-studio-20197zip

Unresolved External Symbol while trying to use bit7z library C++ / Qt


I've been trying to install and properly link bit7z into my C++ code as I have to do a task for my internship which concludes in automatically zipping a certain directory and sending the zip-file out as an email. Right now the email is not interesting to me as I can't even get the base program. I just keep getting the Linker Error 2019 and I don't know what to do anymore. I'll provide as much info as I can.
I use Visual Studio 2019.

My .pro file:

TEMPLATE = app
TARGET = aixLogger
DESTDIR = ./Debug
CONFIG += debug console
DEPENDPATH += .
MOC_DIR += .
OBJECTS_DIR += debug
UI_DIR += GeneratedFiles
RCC_DIR += GeneratedFiles

LIBS += -D:/local/aretz/Programmierung/git-workplace/aixLogger/Dependencies/bit7z/lib -lbit7z
INCLUDEPATH += D:/local/aretz/Programmierung/git-workplace/aixLogger/Dependencies/bit7z/include

include(aixLogger.pri)

My .h

#pragma once
#include <qwidget.h>
#include <qobject.h>
#include <bit7z.hpp>

class AIXLogger : public QWidget
{
    Q_OBJECT
public slots:

public:

    void CompressDir();
    void Execute();
};

My .cpp

#include <QCoreApplication>
#include <string>
#include <iostream>
#include <filesystem>
#include <bit7z.hpp>
#include "main.h"
#include "bitcompressor.hpp"

namespace fs = std::filesystem;
using namespace bit7z;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    std::string path = "C:/Users/aretz/Downloads/test";
    for (const auto& entry : fs::directory_iterator(path))
    std::cout << entry.path() << std::endl;

    //return a.exec();
}

void AIXLogger::CompressDir() {
    try {
        Bit7zLibrary lib{ L"C:/Program Files/7-Zip/7z.dll" };
        //BitCompressor compressor{ lib, BitFormat::Zip };

        std::vector< std::wstring > files = { L"aretz/downloads/test/test1.txt", L"aretz/downloads/test/test1.txt" };

        //Zip Archiv erstellen
        //compressor.compress(files, L"output_archive.zip");

        //Directory zippen
        //compressor.compressDirectory(L"dir/path/", L"dir_archive.zip");

    }
    catch (const BitException& ex) {
        //irgendwas mit &ex machen
    }
}

void AIXLogger::Execute() {

    CompressDir();
}

I'm also adding pictures of the properties I changed.
Additional Dependencies
Additional Library Directories
Additional Include Directories

EDIT: Here is the actual Error I'm getting with just the line "Bit7zLibrary lib {L"C:/Program Files/7-Zip/7z.dll" };:

Error   LNK2019 unresolved external symbol "public: __thiscall bit7z::Bit7zLibrary::Bit7zLibrary(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &)" (??0Bit7zLibrary@bit7z@@QAE@ABV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@Z) referenced in function "public: void __thiscall AIXLogger::CompressDir(void)" (?CompressDir@AIXLogger@@QAEXXZ)   aixLogger   D:\local\aretz\Programmierung\git-workplace\aixLogger\main.obj  1   

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "public: virtual __thiscall bit7z::Bit7zLibrary::~Bit7zLibrary(void)" (??1Bit7zLibrary@bit7z@@UAE@XZ) referenced in function "public: void __thiscall AIXLogger::CompressDir(void)" (?CompressDir@AIXLogger@@QAEXXZ) aixLogger   D:\local\aretz\Programmierung\git-workplace\aixLogger\main.obj  1   

Solution

  • The problem you're having is that the linker cannot find the bit7z static library.

    By default, the bit7z library is built to bit7z\bin\$(PlatformShortName)\, where $(PlatformShortName) is either x86 or x64 according to your target architecture.

    However, you specified a different library directory (bit7z\lib\), which is wrong (unless you changed the directory where you output the built library).

    You can fix it by changing the path to $(SolutionDir)Dependencies\bit7z\bin\$(PlatformShortName)\.

    Also, please note that, on x86, the default library name is just bit7z.lib, while on x64 is bit7z64.lib.