0

I've being trying to compile some code that uses the functions from the unzip.h header and when I try to build it shows me the following errors:

> 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`

As for environment I use VS 2017, zlib 1.2.8, and also downloaded the zdll.lib and linked it with my code by using #pragma comment(lib, "zdll.lib").

To be more precise I found here an algorithm of how I can unarchive a .zip file based on the unzip.h functions and copy the content of a certain file into a buffer:

#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;
}
  • Try to change Visual Studio project configuration. Under General > Common Language Runtime Support set /clr instead of /clr:pure. – Dmytro Dadyka Feb 24 '19 at 15:25
  • 1
    Possible duplicate of [I can't compile a solution due to "Error LNK2028: unresolved token..."](https://stackoverflow.com/questions/19022481/i-cant-compile-a-solution-due-to-error-lnk2028-unresolved-token) – Dmytro Dadyka Feb 24 '19 at 15:25
  • Still not working @DmytroDadyka :/ . I got even more errors – Alex Ionita Feb 24 '19 at 17:44
  • the posted code is C++, please remove the 'c' tag – user3629249 Feb 24 '19 at 18:45
  • @user3629249 the problem is related to the linkage between c code and c++. – Alex Ionita Feb 24 '19 at 19:30
  • C++ mangles names, especially function names, so either the header file for the 'z' library contains the statements: `#ifdef __cplusplus extern "C" { #endif ... // body of header #ifdef __cplusplus } // closing brace for extern "C" #endif` or you will need to wrap the #include of the header file. [details at](https://www.oracle.com/technetwork/articles/servers-storage-dev/mixingcandcpluspluscode-305840.html) – user3629249 Feb 24 '19 at 19:35

0 Answers0