我试图将QuaZip添加到我的项目中,但出现构建错误,所有错误均与未定义的引用有关。
这是第一个错误,它们主要与extractAll函数中的存档函数有关。
错误:对`_imp___ZN6QuaZip13goToFirstFileEv'的未定义引用
这是我的.pro文件的附加内容:
INCLUDEPATH += $$PWD/quazip/
LIBS += -L$$PWD/libs/
INCLUDEPATH += $$PWD/zlib/include/
INCLUDEPATH += $$PWD/zlib/lib/
LIBS += -L$$PWD/zlib/lib/
在quazip子文件夹中,我具有quazip的所有标题。
在libs文件夹之后的那一行中,我有一个用于quazip的.a。
zilib子文件夹具有zlib开发人员文件。
这是我要使用的功能:
void Utilities::updateFiles_zip()
{
currentDownloads.clear();
init_files();
QString error = "";
QString file = "LAE-Intnl-numbers-new.zip";
error = checkForUpdates(file);
if (error != "")
{
errorMessage = error;
if (DEBUG)
qDebug() << "error = {" << error << "}";
return;
}
QString filename = downloadPath + "LAE-Intnl-numbers-new.zip";
QuaZip *zip_file = new QuaZip(filename);
extractAll(zip_file, inputPath);
}
void Utilities::extractAll( QuaZip *archive, QString destFileFolder )
{
// extracts all files from the archive and saves
// them onto disk
//
// just a simple implementation for evaluation.
// error handling has not been implemented yet!
for( bool f = archive->goToFirstFile(); f; f = archive->goToNextFile() )
{
// set source file in archive
QString filePath = archive->getCurrentFileName();
QuaZipFile zFile( archive->getZipName(), filePath );
// open the source file
zFile.open( QIODevice::ReadOnly );
// create a bytes array and write the file data into it
QByteArray ba = zFile.readAll();
// close the source file
zFile.close();
// set destination file
QString destFilePath = destFileFolder + filePath;
QFile dstFile( destFilePath );
// open the destination file
dstFile.open( QIODevice::WriteOnly | QIODevice::Text );
// write the data from the bytes array into the destination file
dstFile.write( ba.data() );
//close the destination file
dstFile.close();
}
}
编辑:符合要求,但应用程序现在崩溃。
这是我的.pro文件的外观:
#-------------------------------------------------
#
# Project created by QtCreator 2013-04-20T05:16:50
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Lottery
TEMPLATE = app
INCLUDEPATH += $$PWD/zlib/include
INCLUDEPATH += $$PWD/zlib/lib
LIBS += -L$$PWD/zlib/lib
LIBS += -L$$PWD/libs/ -lquazip
SOURCES += main.cpp \
mainwindow.cpp \
Games.cpp \
Config.cpp \
ProcessNumbers.cpp \
SortMethods.cpp \
Headers.cpp \
AnalysisMethods.cpp \
CombosMethods.cpp \
CheckMatchesMethods.cpp \
MatchesMethods.cpp \
RandomMethods.cpp \
form.cpp \
Utilities.cpp \
numbersranksavgsdiffs.cpp \
MatchesMethods_LM.cpp
HEADERS += mainwindow.h \
AnalysisMethods.h \
Config.h \
Headers.h \
ProcessNumbers.h \
SortMethods.h \
dates.h \
sorts.h \
update.h \
Games.h \
CombosMethods.h \
combos.h \
gameballs.h \
comboscheck.h \
CheckMatchesMethods.h \
MatchesMethods.h \
RandomMethods.h \
checkmatches.h \
progress.h \
form2.h \
matches.h \
random.h \
Utilities.h \
pointers.h \
diffs.h \
numbersranksavgsdiffs.h \
MatchesMethods_LM.h \
matches_lm.h \
analysis.h
include(quazip.pri)
FORMS += \
mainwindow.ui \
dates.ui \
update.ui \
sorts.ui \
combos.ui \
gameballs.ui \
comboscheck.ui \
checkmatches.ui \
form2.ui \
progress.ui \
matches.ui \
random.ui \
diffs.ui \
matches_lm.ui \
analysis.ui
QT += network
QT += core gui widgets
QT += concurrent
#QMAKE_LFLAGS_WINDOWS += -Wl,--stack,32000000
#QMAKE_LFLAGS += /STACK:32000000
#QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS,5.01
RC_ICONS = currency_blue_dollar.ico
这是我的quazip.pri外观:
#INCLUDEPATH += $$PWD/quazip
#DEPENDPATH += $$PWD/quazip
INCLUDEPATH += $$PWD/quazip/headers
HEADERS += $$PWD/quazip/headers/minizip_crypt.h \
$$PWD/quazip/headers/ioapi.h \
$$PWD/quazip/headers/JlCompress.h \
$$PWD/quazip/headers/quaadler32.h \
$$PWD/quazip/headers/quachecksum32.h \
$$PWD/quazip/headers/quacrc32.h \
$$PWD/quazip/headers/quagzipfile.h \
$$PWD/quazip/headers/quaziodevice.h \
$$PWD/quazip/headers/quazipdir.h \
$$PWD/quazip/headers/quazipfile.h \
$$PWD/quazip/headers/quazipfileinfo.h \
$$PWD/quazip/headers/quazip_global.h \
$$PWD/quazip/headers/quazip.h \
$$PWD/quazip/headers/quazipnewinfo.h \
$$PWD/quazip/headers/unzip.h \
$$PWD/quazip/headers/zip.h
# $$PWD/zlib/include/zlib.h
#SOURCES += $$PWD/quazip/qioapi.cpp \
# $$PWD/quazip/JlCompress.cpp \
# $$PWD/quazip/quaadler32.cpp \
# $$PWD/quazip/quacrc32.cpp \
# $$PWD/quazip/quagzipfile.cpp \
# $$PWD/quazip/quaziodevice.cpp \
# $$PWD/quazip/quazip.cpp \
# $$PWD/quazip/quazipdir.cpp \
# $$PWD/quazip/quazipfile.cpp \
# $$PWD/quazip/quazipfileinfo.cpp \
# $$PWD/quazip/quazipnewinfo.cpp \
# $$PWD/quazip/unzip.c \
# $$PWD/quazip/zip.c
最佳答案
为什么不将源代码放在您喜欢的任何目录中。例如,3rdparty:
|-- project.pro
|-- ....
|-- 3rdparty\
| |-- QuaZip\
| |
将以下行添加到您的qmake项目文件中:
include(3rdparty/quazip/blob/master/quazip.pri)
并且
qmake
会完成这项工作