我正在尝试使用libzip编写一个简单的培训程序来列出存档的内容(目前的目标是:)。我正在使用libzip来源。

.pro文件:

QT += widgets

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

INCLUDEPATH = /path/to/libzip

HEADERS += \
    myZip.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()));

}


main.cpp

#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一起使用也不起作用。

最佳答案

您有两种选择:


将libzip构建为静态库,然后将您的项目链接到该静态库
将libzip的源文件添加到您的项目中

关于c++ - 在OSX山狮上将libzip与Qt 5一起使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14249327/

10-10 20:57