我正在尝试编译一些使用unzip.h标头中的函数的代码,当我尝试构建它时,向我显示以下错误:
> 1>unzip.obj : error LNK2028: unresolved token (0A000068) "extern "C"
> long __cdecl call_zseek64(struct zlib_filefunc64_32_def_s const *,void
> *,unsigned __int64,int)" (?call_zseek64@@$$J0YAJPBUzlib_filefunc64_32_def_s@@PAX_KH@Z)
> referenced in function "unsigned __int64 __cdecl `anonymous
> namespace'::unz64local_SearchCentralDir(struct
> zlib_filefunc64_32_def_s const *,void *)"
> (?unz64local_SearchCentralDir@?A0x85240b22@@$$FYA_KPBUzlib_filefunc64_32_def_s@@PAX@Z)
>
> 1>unzip.obj : error LNK2028: unresolved token (0A000081) "extern "C" void __cdecl fill_zlib_filefunc64_32_def_from_filefunc32(struct
> zlib_filefunc64_32_def_s *,struct zlib_filefunc_def_s const *)"
> (?fill_zlib_filefunc64_32_def_from_filefunc32@@$$J0YAXPAUzlib_filefunc64_32_def_s@@PBUzlib_filefunc_def_s@@@Z)
> referenced in function "extern "C" void * __cdecl unzOpen2(char const
> *,struct zlib_filefunc_def_s *)" (?unzOpen2@@$$J0YAPAXPBDPAUzlib_filefunc_def_s@@@Z)
> 1>unzip.obj : error LNK2028: unresolved token (0A000084) "extern "C" void __cdecl fill_fopen64_filefunc(struct zlib_filefunc64_def_s
> *)" (?fill_fopen64_filefunc@@$$J0YAXPAUzlib_filefunc64_def_s@@@Z) referenced in function "void * __cdecl `anonymous
> namespace'::unzOpenInternal(void const *,struct
> zlib_filefunc64_32_def_s *,int)"
> (?unzOpenInternal@?A0x85240b22@@$$FYAPAXPBXPAUzlib_filefunc64_32_def_s@@H@Z)
>
> 1>unzip.obj : error LNK2028: unresolved token (0A000087) "extern "C" void * __cdecl call_zopen64(struct zlib_filefunc64_32_def_s const
> *,void const *,int)" (?call_zopen64@@$$J0YAPAXPBUzlib_filefunc64_32_def_s@@PBXH@Z)
> referenced in function "void * __cdecl `anonymous
> namespace'::unzOpenInternal(void const *,struct
> zlib_filefunc64_32_def_s *,int)"
> (?unzOpenInternal@?A0x85240b22@@$$FYAPAXPBXPAUzlib_filefunc64_32_def_s@@H@Z)
>
> 1>unzip.obj : error LNK2028: unresolved token (0A000089) "extern "C" unsigned __int64 __cdecl call_ztell64(struct
> zlib_filefunc64_32_def_s const *,void *)"
> (?call_ztell64@@$$J0YA_KPBUzlib_filefunc64_32_def_s@@PAX@Z) referenced
> in function "unsigned __int64 __cdecl `anonymous
> namespace'::unz64local_SearchCentralDir(struct
> zlib_filefunc64_32_def_s const *,void *)"
> (?unz64local_SearchCentralDir@?A0x85240b22@@$$FYA_KPBUzlib_filefunc64_32_def_s@@PAX@Z)
>
> 1>unzip.obj : error LNK2019: unresolved external symbol "extern "C" long __cdecl call_zseek64(struct zlib_filefunc64_32_def_s const
> *,void
> *,unsigned __int64,int)" (?call_zseek64@@$$J0YAJPBUzlib_filefunc64_32_def_s@@PAX_KH@Z)
> referenced in function "unsigned __int64 __cdecl `anonymous
> namespace'::unz64local_SearchCentralDir(struct
> zlib_filefunc64_32_def_s const *,void *)"
> (?unz64local_SearchCentralDir@?A0x85240b22@@$$FYA_KPBUzlib_filefunc64_32_def_s@@PAX@Z)
>
> 1>unzip.obj : error LNK2019: unresolved external symbol "extern "C" unsigned __int64 __cdecl call_ztell64(struct
> zlib_filefunc64_32_def_s const *,void *)"
> (?call_ztell64@@$$J0YA_KPBUzlib_filefunc64_32_def_s@@PAX@Z) referenced
> in function "unsigned __int64 __cdecl `anonymous
> namespace'::unz64local_SearchCentralDir(struct
> zlib_filefunc64_32_def_s const *,void *)"
> (?unz64local_SearchCentralDir@?A0x85240b22@@$$FYA_KPBUzlib_filefunc64_32_def_s@@PAX@Z)
>
> 1>unzip.obj : error LNK2019: unresolved external symbol "extern "C" void __cdecl fill_fopen64_filefunc(struct zlib_filefunc64_def_s
> *)" (?fill_fopen64_filefunc@@$$J0YAXPAUzlib_filefunc64_def_s@@@Z) referenced in function "void * __cdecl `anonymous
> namespace'::unzOpenInternal(void const *,struct
> zlib_filefunc64_32_def_s *,int)"
> (?unzOpenInternal@?A0x85240b22@@$$FYAPAXPBXPAUzlib_filefunc64_32_def_s@@H@Z)
>
> 1>unzip.obj : error LNK2019: unresolved external symbol "extern "C" void * __cdecl call_zopen64(struct zlib_filefunc64_32_def_s const
> *,void const *,int)" (?call_zopen64@@$$J0YAPAXPBUzlib_filefunc64_32_def_s@@PBXH@Z)
> referenced in function "void * __cdecl `anonymous
> namespace'::unzOpenInternal(void const *,struct
> zlib_filefunc64_32_def_s *,int)"
> (?unzOpenInternal@?A0x85240b22@@$$FYAPAXPBXPAUzlib_filefunc64_32_def_s@@H@Z)
>
>
> 1>unzip.obj : error LNK2019: unresolved external symbol "extern "C"
> void __cdecl fill_zlib_filefunc64_32_def_from_filefunc32(struct
> zlib_filefunc64_32_def_s *,struct zlib_filefunc_def_s const *)"
> (?fill_zlib_filefunc64_32_def_from_filefunc32@@$$J0YAXPAUzlib_filefunc64_32_def_s@@PBUzlib_filefunc_def_s@@@Z)
> referenced in function "extern "C" void * __cdecl unzOpen2(char const
> *,struct zlib_filefunc_def_s *)" (?unzOpen2@@$$J0YAPAXPBDPAUzlib_filefunc_def_s@@@Z)
> 1>C:\Users\Alexandru Ionita\source\repos\Anaf_Interogare\Debug\Anaf_Interogare.exe : fatal
> error LNK1120: 10 unresolved externals`
对于环境,我使用VS 2017,zlib 1.2.8,还下载了zdll.lib,并使用#pragma comment(lib, "zdll.lib")
将其链接到我的代码。
更精确地说,我在这里找到了一种算法,该算法可以基于unzip.h函数解压缩.zip文件并将特定文件的内容复制到缓冲区中:
#pragma once
#pragma comment (lib, "C:\\Users\\Alexandru Ionita\\Downloads\\zdll.lib")
#include <cstdio>
#include <string>
#include <iostream>
#include "C:\\Users\\Alexandru `Ionita\\source\\repos\\Project1\\Project1\\contrib\\minizip\\unzip.h" // MiniZip library`
#define WRITEBUFFERSIZE (5242880) // 5Mb buffer
using namespace std;
string readZipFile(string zipFile, string fileInZip) {
int err = UNZ_OK; // error status
uInt size_buf = WRITEBUFFERSIZE; // byte size of buffer to store raw csv data
void* buf; // the buffer
string sout; // output strings
char filename_inzip[256]; // for unzGetCurrentFileInfo
unz_file_info file_info; // for unzGetCurrentFileInfo
unzFile uf = unzOpen(zipFile.c_str()); // open zipfile stream
if (uf == NULL) {
cerr << "Cannot open " << zipFile << endl;
return sout;
} // file is open
if (unzLocateFile(uf, fileInZip.c_str(), 1)) { // try to locate file inside zip
// second argument of unzLocateFile: 1 = case sensitive, 0 = case-insensitive
cerr << "File " << fileInZip << " not found in " << zipFile << endl;
return sout;
} // file inside zip found
if (unzGetCurrentFileInfo(uf, &file_info, filename_inzip, sizeof(filename_inzip), NULL, 0, NULL, 0)) {
cerr << "Error " << err << " with zipfile " << zipFile << " in unzGetCurrentFileInfo." << endl;
return sout;
} // obtained the necessary details about file inside zip
buf = (void*)malloc(size_buf); // setup buffer
if (buf == NULL) {
cerr << "Error allocating memory for read buffer" << endl;
return sout;
} // buffer ready
err = unzOpenCurrentFilePassword(uf, NULL); // Open the file inside the zip (password = NULL)
if (err != UNZ_OK) {
cerr << "Error " << err << " with zipfile " << zipFile << " in unzOpenCurrentFilePassword." << endl;
return sout;
} // file inside the zip is open
// Copy contents of the file inside the zip to the buffer
cout << "Extracting: " << filename_inzip << " from " << zipFile << endl;
do {
err = unzReadCurrentFile(uf, buf, size_buf);
if (err < 0) {
cerr << "Error " << err << " with zipfile " << zipFile << " in unzReadCurrentFile" << endl;
sout = ""; // empty output string
break;
}
// copy the buffer to a string
if (err > 0) for (int i = 0; i < (int)err; i++) sout.push_back(*(((char*)buf) + i));
} while (err > 0);
err = unzCloseCurrentFile(uf); // close the zipfile
if (err != UNZ_OK) {
cerr << "Error " << err << " with zipfile " << zipFile << " in unzCloseCurrentFile" << endl;
sout = ""; // empty output string
}
free(buf); // free up buffer memory
return sout;
}