I'm trying to make a simple program for training using the libzip to list the content of an archive (goal for now :). I'm using the libzip sources.
.pro file:
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()));
}
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();
}
The problem is when I compile, I get the following message:
symbol(s) not found for architecture x86_64
collect2: ld return exit status
And when I look to the output I have
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
Any idea on how I could solve the problem? I could not find any solution...
For info I followed this tutoriel on how using the libzip [in French]: http://slash.developpez.com/tutoriels/c/utilisation-libzip/
Configuration: Qt 5.0.0 on OSX Mountain Lion with clang_64 compiler (default)
Thanks
WDeadpool
PS: When adapting the code, it does not work either using qt 4.8.1 with gcc.
You have two choices: