0

我正在尝试使用 libzip 制作一个简单的训练程序来列出存档的内容(现在的目标:)。我正在使用 libzip 源。

。轮廓:

QT += widgets

SOURCES += \
    main.cpp \
    myZip.cpp \

INCLUDEPATH = /path/to/libzip

HEADERS += \
    myZip.h \

MCZip.h

#include <QtWidgets>
#include "zip.h"

class myZip : public QDialog
{
public:
    myZip(const char* filePath);

private:
    QTextEdit *m_fileListView;
    QString m_fileList;

    QPushButton *m_closeButton;

};

myZip.cpp

#include "my.h"

myZip::myZip(const char* filePath)
{
    setFixedSize(400, 400);

    m_fileListView = new QTextEdit;
    m_closeButton = new QPushButton("Close");

    int err = 0;
    struct zip *f_zip=NULL;

    f_zip = zip_open(filePath, ZIP_CHECKCONS, &err);

    if(err != ZIP_ER_OK)
    {
        QMessageBox::critical(this, "Error", "Cannot open the file!");
        return;
    }

    if(f_zip == NULL)
    {
        QMessageBox::critical(this, "Error", "File not found");
        return;
    }

    int fileCount = zip_get_num_files(f_zip);
    if (fileCount ==-1)
    {
        QMessageBox::critical(this, "Error", "The archive seems corrupted");
        return;
    }

    qDebug() << QString("There are %1 files in the archive").arg(fileCount);

    for (int i = 0; i < fileCount; i++)
    {
        m_fileList += QString(QString::fromLocal8Bit(zip_get_name(f_zip, i, ZIP_FL_UNCHANGED)) + "\n");
    }

    zip_close(f_zip);
    f_zip = NULL;

    m_fileListView->setText(m_fileList);

    QHBoxLayout *layout = new QHBoxLayout;
    layout->addWidget(m_fileListView);
    layout->addWidget(m_closeButton);

    setLayout(layout);

    QObject::connect(m_closeButton, SIGNAL(clicked()), this, SLOT(close()));

}

主文件

#include <QApplication>
#include "MCCover.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QString filePath = QFileDialog::getOpenFileName(this, "Open a file", QString(),
                                             "Zip archive (*.zip)"); 

    QByteArray byteArray = filePath.toUtf8();
    const char* cFilePath = byteArray.constData();

    myZip *fileList = new myZip(cFilePath);
    fileList.show();

    return app.exec();
}

问题是当我编译时,我收到以下消息:

symbol(s) not found for architecture x86_64
collect2: ld return exit status

当我查看输出时

Undefined symbols for architecture x86_64:
        "_zip_close", referenced from:
              myZip::myZip(char const*)in myZip.o
              myZip::myZip(char const*)in myZip.o
        "_zip_get_name", referenced from:
              myZip::myZip(char const*)in myZip.o
              myZip::myZip(char const*)in myZip.o
        "_zip_get_num_files", referenced from:
              myZip::myZip(char const*)in myZip.o
              myZip::myZip(char const*)in myZip.o
        "_zip_open", referenced from:
              myZip::myZip(char const*)in myZip.o
              myZip::myZip(char const*)in myZip.o
 ld: symbol(s) not found for architecture x86_64
 collect2: ld returned 1 exit status

关于如何解决问题的任何想法?我找不到任何解决方案...

有关如何使用 libzip [法语] 的信息,我遵循了本教程:http: //slash.developpez.com/tutoriels/c/utilisation-libzip/

配置:带有 clang_64 编译器的 OSX Mountain Lion 上的 Qt 5.0.0(默认)

谢谢

死侍

PS:在修改代码时,使用 qt 4.8.1 和 gcc 都不起作用。

4

1 回答 1

2

你有两个选择:

  • 将 libzip 构建为静态库,然后将您的项目链接到此静态库
  • 将 libzip 的源文件添加到您的项目中
于 2013-01-10T03:00:21.213 回答