Giter Site home page Giter Site logo

libzippp's Introduction

Build Status

LIBZIPPP

libzippp is a simple basic C++ wrapper around the libzip library. It is meant to be a portable and easy-to-use library for ZIP handling.

Compilation has been tested with:

  • GCC 9 (Travis CI)
  • GCC 11.2.0 (GNU/Linux Debian)
  • MS Visual Studio 2012 (Windows 7)

Underlying libraries:

For more info on available compression methods, see here.

Integration

libzippp has been ported to vcpkg and thus can be very easily integrated by running:

./vcpkg install libzippp

Compilation

Install Prerequisites

This library requires at least C++ 11 to be compiled.

  • Linux

    • Install the development packages for zlib and libzip (e.g. zlib1g-dev, libzip-dev, liblzma-dev, libbz2-dev).
    • It is possible to use the Makefile by executing make libraries.
  • Windows:

    • Use precompiled libraries from libzippp-<version>-windows-ready_to_compile.zip.
    • Install from source via CMake (similar to workflow below).
  • All Operating systems

    • If it is intended to be used with encryption it is necessary to compile libzip with any encryption and to enable it in libzippp through the cmake flag LIBZIPPP_ENABLE_ENCRYPTION.

Compile libzippp

Quick start

mkdir build
cd build
cmake ..
make
make install

Step by step

  • Make sure you have a compiler (MSVC, g++, ...) and CMake installed
  • Switch to the source folder
  • Create a build folder and switch to it, e.g.: mkdir build && cd build
  • Configure the build with cmake:
    • Commandline: cmake .. -DCMAKE_BUILD_TYPE=Release
    • Within the CMake GUI, set source and build folder accordingly
      • Click Add Cache Entry to add CMAKE_BUILD_TYPE if not building with MSVC
      • Click Configure & Generate
    • If CMake can't find zlib and/or libzip you need to set CMAKE_PREFIX_PATH to the directories where you installed those into (either via -DCMAKE_PREFIX_PATH=<...> or via the GUI)
      • Example: -DCMAKE_PREFIX_PATH=/home/user/libzip-1.10.1:/home/user/zlib-1.3.1
  • Compile as usual
    • Linux: make && make install
    • Windows: Open generated project in MSVC. Build the INSTALL target to install.

CMake variables of interest

Set via commandline as cmake -DNAME=VALUE <other opts> or via CMake GUI or CCMake Add Cache Entry.

  • LIBZIPPP_INSTALL: Enable/Disable installation of libzippp. Default is OFF when using via add_subdirectory, else ON
  • LIBZIPPP_INSTALL_HEADERS: Enable/Disable installation of libzippp headers. Default is OFF when using via add_subdirectory, else ON
  • LIBZIPPP_BUILD_TESTS: Enable/Disable building libzippp tests. Default is OFF when using via add_subdirectory, else ON
  • LIBZIPPP_ENABLE_ENCRYPTION: Enable/Disable building libzippp with encryption capabilities. Default is OFF.
  • LIBZIPPP_CMAKE_CONFIG_MODE: Enable/Disable building with libzip installed cmake config files. Default is OFF.
  • LIBZIPPP_GNUINSTALLDIRS: Enable/Disable building with install directories taken from GNUInstallDirs. Default is OFF.
  • CMAKE_INSTALL_PREFIX: Where to install the project to
  • CMAKE_BUILD_TYPE: Set to Release or Debug to build with or without optimizations
  • CMAKE_PREFIX_PATH: Colon-separated list of prefix paths (paths containing lib and include folders) for installed libs to be used by this
  • BUILD_SHARED_LIBS: Set to ON or OFF to build shared or static libs, uses platform default if not set

Referencing libzippp

Once installed libzippp can be used from any CMake project with ease:
Given that it was installed (via CMAKE_INSTALL_PREFIX) into a standard location or its install prefix is passed into your projects CMAKE_PREFIX_PATH you can simply call find_package(libzippp 3.0 REQUIRED) and link against libzippp::libzippp.

When not using CMake to consume libzippp you have to pass its include directory to your compiler and link against libzippp.{a,so}. Do not forget to also link against libzip libraries e.g. in lib/libzip-1.10.1/lib/.libs/). An example of compilation with g++:

g++ -I./src \
    -I./lib/libzip-1.10.1/lib I./lib/libzip-1.10.1/build \
    main.cpp libzippp.a \
    lib/libzip-1.10.1/lib/.libs/libzip.a \
    lib/zlib-1.3.1/libz.a

Encryption

Since version 1.5, libzip uses an underlying cryptographic library (OpenSSL, GNUTLS or CommonCrypto) that is necessary for static compilation. By default, libzippp will use -lssl -lcrypto (OpenSSL) as default flags to compile the tests. This can be changed by using make CRYPTO_FLAGS="-lsome_lib" LIBZIP_CMAKE="" tests.

Since libzip cmake's file detects automatically the cryptographic library to use, by default all the allowed libraries but OpenSSL are explicitely disabled in the LIBZIP_CMAKE variable in the Makefile.

See here for more information.

WINDOWS - Alternative way

The easiest way is to download zlib, libzip and libzippp sources and use CMake GUI to build each library in order:

  • Open CMake GUI
  • Point Source to the libraries source folder, Build to a new folder build inside it
  • Run Generate
  • Open the generated solution in MSVC and build & install it
  • Repeat for the next library

But there is also a prepared batch file to help automate this. It may need some adjusting though.

From Stage 1 - Use prepared environment

  1. Make sure you have cmake 3.20 (cmake.exe must be in the PATH) and MS Visual Studio.

  2. Download the libzippp-<version>-windows-ready_to_compile.zip file from the release and extract it somewhere on your system. This will create a prepared structure, so libzippp can be compiled along with the needed libraries.

  3. Check if there is any patch to apply in lib. Sometimes, some files are not compilable in C89 in libzip, depending on the version.

  4. Simply execute the compile.bat file. This will compile zlib, libzip and finally libzippp.

  5. You'll have a dist folder containing the release and debug folders where you can now execute the libzippp tests.

From Stage 0 - DIY

  1. Make sure you have cmake 3.10 (cmake.exe must be in the PATH) and MS Visual Studio 2012.

  2. Download libzip and zlib sources and extract them in the 'lib' folder. You should end up with the following structure:

libzippp/compile.bat
libzippp/lib/zlib-1.3.1
libzippp/lib/libzip-1.10.1
  1. Execute the compile.bat (simply double-click on it). The compilation should go without error.

  2. You'll have a dist folder containing the release and debug folders where you can now execute the libzippp tests.

  3. You can either use libzippp.dll and libzippp.lib to link dynamically the library or simply use libzippp_static.lib to link it statically. Unless you also link zlib and libzippp statically, you'll need the dll packaged with your executable.

Usage

The API is meant to be very straight forward. Some french explanations can be found here.

List and read files in an archive

#include "libzippp.h"
using namespace libzippp;

int main(int argc, char** argv) {
  ZipArchive zf("archive.zip");
  zf.open(ZipArchive::ReadOnly);

  vector<ZipEntry> entries = zf.getEntries();
  vector<ZipEntry>::iterator it;
  for(it=entries.begin() ; it!=entries.end(); ++it) {
    ZipEntry entry = *it;
    string name = entry.getName();
    int size = entry.getSize();

    //the length of binaryData will be given by 'size'
    void* binaryData = entry.readAsBinary();

    //the length of textData will be given by 'size'
    string textData = entry.readAsText();

    //...
  }

  zf.close();
  
  return 0;
}

You can also create an archive directly from a buffer

#include "libzippp.h"
using namespace libzippp;

int main(int argc, char** argv) {
  char* buffer = someData;
  uint32_t bufferSize = sizeOfBuffer;

  ZipArchive* zf = ZipArchive::fromBuffer(buffer, bufferSize);
  if(zf!=nullptr) {
    /* work with the ZipArchive instance */
    zf->close();
    delete zf;
  }
  
  return 0;
}

Read a specific entry from an archive

#include "libzippp.h"
using namespace libzippp;

int main(int argc, char** argv) {
  ZipArchive zf("archive.zip");
  zf.open(ZipArchive::ReadOnly);

  //raw access
  char* data = (char*)zf.readEntry("myFile.txt", true);
  ZipEntry entry1 = zf.getEntry("myFile.txt");
  string str1(data, entry1.getSize());

  //text access
  ZipEntry entry2 = zf.getEntry("myFile.txt");
  string str2 = entry2.readAsText();

  zf.close();
  
  return 0;
}

Read a large entry from an archive

#include "libzippp.h"
using namespace libzippp;

int main(int argc, char** argv) {
  ZipArchive zf("archive.zip");
  zf.open(ZipArchive::ReadOnly);

  ZipEntry largeEntry = z1.getEntry("largeentry");
  std::ofstream ofUnzippedFile("largeFileContent.data");
  largeEntry.readContent(ofUnzippedFile);
  ofUnzippedFile.close();

  zf.close();

  return 0;
}

Add data to an archive

#include "libzippp.h"
using namespace libzippp;

int main(int argc, char** argv) {
  ZipArchive zf("archive.zip");
  zf.open(ZipArchive::Write);

  
#ifdef LIBZIPPP_USE_BZIP2
  // Advanced usage : change the compression method. Default is DEFLATE.
  zf.setCompressionMethod(entry, CompressionMethod::BZIP2);
#endif

  zf.addEntry("folder/subdir/");

  const char* textData = "Hello,World!";
  zf.addData("helloworld.txt", textData, 12);

  zf.close();

  return 0;
}

Remove data from an archive

#include "libzippp.h"
using namespace libzippp;

int main(int argc, char** argv) {
  ZipArchive zf("archive.zip");
  zf.open(ZipArchive::Write);
  zf.deleteEntry("myFile.txt");
  zf.deleteEntry("myDir/subDir/");
  zf.close();
  
  return 0;
}

Progression of committed changes

#include "libzippp.h"
using namespace libzippp;

class SimpleProgressListener : public ZipProgressListener {
public:
    SimpleProgressListener(void) {}
    virtual ~SimpleProgressListener(void) {}

    void progression(double p) {
        cout << "-- Progression: " << p << endl;
    }
};

int main(int argc, char** argv) {
  ZipArchive zf("archive.zip");
  /* add/modify/delete entries in the archive */

  //register the listener
  SimpleProgressListener spl;
  zf.addProgressListener(&spl);

  //adjust how often the listener will be invoked
  zf.setProgressPrecision(0.1);

  //listener will be invoked
  zf.close();

  return 0;
}

In-memory archives

#include "libzippp.h"
using namespace libzippp;

int main(int argc, char** argv) {
  //important to use calloc/malloc for the fromWritableBuffer !
  void* buffer = calloc(4096, sizeof(char));

  ZipArchive* z1 = ZipArchive::fromWritableBuffer(&buffer, 4096, ZipArchive::New);
  /* add content to the archive */
  
  //updates the content of the buffer
  z1->close();

  //length of the buffer content
  int bufferContentLength = z1->getBufferLength();
  
  ZipArchive::free(z1);

  //read again from the archive:
  ZipArchive* z2 = ZipArchive::fromBuffer(buffer, bufferContentLength);
  /* read the archive - no modification allowed */
  ZipArchive::free(z2);
  
  //read again from the archive, for modification:
  ZipArchive* z3 = ZipArchive::fromWritableBuffer(&buffer, bufferContentLength);
  /* read/write the archive */
  ZipArchive::free(z3);
  
  free(buffer);

  return 0;
}

Error handling

By default, the error handling is pretty basic and the errors details are dumped to stderr. However, it is possible to provide a callback method to override this behavior. If some context is required, you may use std::bind or lambda-functions.

#include "libzippp.h"
using namespace libzippp;

int main(int argc, char** argv) {
  ZipArchive zf("archive.zip");
  zf.setErrorHandlerCallback([](const std::string& message,
                                const std::string& strerror,
                                int zip_error_code,
                                int system_error_code)
  {
      // Handle error here
      fprintf(stderr, message.c_str(), strerror.c_str());
  });

  zf.open(ZipArchive::Write);
  zf.addEntry("folder/subdir/");

  const char* textData = "Hello,World!";
  zf.addData("helloworld.txt", textData, 12);

  zf.close();

  return 0;
}

Known issues

LINUX

You might already have libzip compiled elsewhere on your system. Hence, you don't need to run 'make libzip'. Instead, just put the libzip location when you compile libzippp:

make LIBZIP=path/to/libzip

Under Debian, you'll have to install the package zlib1g-dev in order to compile if you don't want to install zlib manually.

WINDOWS

By default, MS Visual Studio 2012 is installed under the following path:

C:\Program Files (x86)\Microsoft Visual Studio 11.0\

Be aware that non-virtual-only classes are shared within the DLL of libzippp. Hence you'll need to use the same compiler for libzippp and the pieces of code that will use it. To avoid this issue, you'll have to link the library statically.

More information here.

Static linkage

Extra explanations can be found here.

Donate

This project is completely developed during my spare time.

Since I'm a big fan of cryptocurrencies and especially Cardano (ADA), you can send me some coins at the address below (check it here):

addr1q9sgms4vc038nq7hu4499yeszy0rsq3hjeu2k9wraksle8arg0n953hlsrtdzpfnxxw996l4t6qu5xsx8cmmakjcqhksaqpj66

libzippp's People

Contributors

alexandrebaiao avatar astroair avatar bob590 avatar ctabin avatar daljit97 avatar embeddedmz avatar flamefire avatar flomnes avatar giuseppecesarano avatar liweimax avatar mmassing avatar n0owud avatar niclasr avatar okaerin avatar shreejanshrestha avatar tyler92 avatar vicroms avatar xiangze-li avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libzippp's Issues

Unable to use libzippp via cmake with vcpkg on Linux/OS X

Using my own project as well as the example project in this repo, I always get the error of not finding libzip::libzip when trying to use libzippp via vcpkg on Linux and OS X.

CMake Error at /home/brian/vcpkg/scripts/buildsystems/vcpkg.cmake:349 (_add_executable):
  Target "example" links to target "libzip::libzip" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
Call Stack (most recent call first):
  CMakeLists.txt:8 (add_executable)

libzip is installed via vcpkg as well:

./vcpkg list
...
bzip2:x64-linux                                    1.0.8            High-quality data compressor.
libzip:x64-linux                                   1.7.1#1          A library for reading, creating, and modifying z...
libzip[bzip2]:x64-linux                                             Support bzip2-compressed zip archives
libzip[default-aes]:x64-linux                                       Use default AES
libzip[openssl]:x64-linux                                           AES (encryption) support using OpenSSL
libzippp:x64-linux                                 3.1-1.6.1        Simple basic C++ wrapper around the libzip libra...
...

Everything works as expected on Windows. Any thoughts on what might be wrong?

Thank you!

readAsText() segfaults

Hello,

Currently using libzippp to view the content of a text file in a zip archive. I called readAsText() and got the following exception in gdb:

Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000020 libzippp::ZipArchive::isOpen (this=0x0) at libzippp.h:146 146 bool isOpen(void) const { return zipHandle!=NULL; }

Add Support for zip_source_function

Any plan to add support for zip_source_function?

wrapping zip_source_function will allow for better performance when writing/reading large zip entries. This will allow users to write to the zip dynamically without the need to read/write to a temp file or a contiguous block of memory

API for adding batch of files

It would be cool to have something like
bool ZipArchive::addData
but providing for instance vector of pairs name->data. Because adding 1000 small files one by one is too slow.

MSVC warning when compiling using find_package & vcpkg

Sorry, I don't have a ton of context on how the cmake integration works with vcpkg etc, but it seems like the settings for MSVC isn't correct somewhere.

C:\.....\vcpkg_installed\x64-windows\include\libzippp\libzippp.h(550): warning C4245: 'initializing': conversion from 'int' to 'libzippp_uint16', signed/unsigned mismatch

vcpkg installs libzippp-v5.0-1.8.0 which differs to what is in the master branch; so this might already be fixed. Looks like when the initialization constants are being passed to ZipEntry they are just int but are being implicitly cast to unsigned int etc.

As I only use libzippp.h in once place, I was able to hide these warnings by doing the following

#ifdef _MSC_VER
#pragma warning(disable: 4245) // disable warning 4345
#endif

#include <libzippp.h>

#ifdef _MSC_VER
#pragma warning(default: 4245) // enable warning 4345 back
#endif

When you google this general problem (like "suppress included library compiler warnings" or something like that) you get some suggestions to use target_include_directories(<target> SYSTEM <dir>) however I think all the magic inside vcpkg find_package means that the include directories part happens automatically and I don't get a chance to set them as SYSTEM. So maybe the long term fix is to have the vcpkg portfile mark the include dir as SYSTEM? Somehow?

Sorry I can't be more specific as I don't understand how the build system all hangs together - I just use it - and for the most part it all works just fine.

Hope report this helps; if not please feel free to close with extreme prejudice ;-)

Unable to compile with VC2015 using libzippp-v2.1-1.5.1-windows-ready_to_compile.zip

I changed compile.bat:
SET vs2012devprompt=C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat

Compiling libzip...
CMake Error at CMakeLists.txt:8 (PROJECT):
Failed to run MSBuild command:

C:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe

to get the value of VCTargetsPath:

Microsoft (R) Build Engine version 4.7.2558.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 2018-06-08 3:22:10 PM.
Project "D:\Documents\Visual_Studio_2015\Projects\MyProject\packages\libzippp-v2.1-1.5.1\lib\libzip-1.5.1\build\CMakeFiles\3.11.3\VCTargetsPath.vcxproj" on node 1 (default targets).
D:\Documents\Visual_Studio_2015\Projects\MyProject\packages\libzippp-v2.1-1.5.1\lib\libzip-1.5.1\build\CMakeFiles\3.11.3\VCTargetsPath.vcxproj(14,2): error MSB4019: The imported project "D:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
Done Building Project "D:\Documents\Visual_Studio_2015\Projects\MyProject\packages\libzippp-v2.1-1.5.1\lib\libzip-1.5.1\build\CMakeFiles\3.11.3\VCTargetsPath.vcxproj" (default targets) -- FAILED.

Build FAILED.

"D:\Documents\Visual_Studio_2015\Projects\MyProject\packages\libzippp-v2.1-1.5.1\lib\libzip-1.5.1\build\CMakeFiles\3.11.3\VCTargetsPath.vcxproj" (default target) (1) ->
  D:\Documents\Visual_Studio_2015\Projects\MyProject\packages\libzippp-v2.1-1.5.1\lib\libzip-1.5.1\build\CMakeFiles\3.11.3\VCTargetsPath.vcxproj(14,2): error MSB4019: The imported project "D:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.14

Exit code: 1

-- Configuring incomplete, errors occurred!
See also "D:/Documents/Visual_Studio_2015/Projects/MyProject/packages/libzippp-v2.1-1.5.1/lib/libzip-1.5.1/build/CMakeFiles/CMakeOutput.log".
[ERROR] Unable to compile libzip
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

How to extract to a directory

Not an issue ! I would like to use your API but I did not see the method for extracting all files and subdirectories from an archive into a desired directory. In the same way, how to zip a whole directory with all these files and subdirectories ? Have I to myself iterate recursively for each files for each directory and add or read files ? Sound weird I just want to zip and unzip a directory but not working directly in the archive ! How to do that easily ?

ZipArchive.addData() length parameters is not 64 bit compatible

The length parameter is defined as 32 bit, when in a 64 bit process it can be larger than a 32 bit unsigned integer .
Current:

 bool addData(const std::string& entryName, const void* data, uint length, bool freeData=false) const;

New:

 bool addData(const std::string& entryName, const void* data, libzippp_uint64 length, bool freeData=false) const;

Error when build with libzippp_static.lib

Lib was success built with VS2017 (VC++ 14) with a little modify in compile.bat.
I created a new solution with the origin tests.cpp to try build an application without any DLL but failed.

Error are:
LNK2001 unresolved external symbol __imp_remove
LNK2001 unresolved external symbol __imp_zip_close
...

I found a similar issue(#4) here with different error messages (which error messages of unresolved external symbol have no __imp prefix).

Does I miss something or could you update a simple guild to help build static lib?

Use a write function for readEntry?

I want to read an entry to my custom buffer, but I find it's not easy to use it in readEntry. Would you like to add a new version that accepts std::function<bool(const char*,libzippp_uint64)>?
Just replace ofOutput.write(data, size); if (!ofOutput) {...} with if (!writeFunc(data, size)) {...} and the std::ostream version can use

[=](const char* data,libzippp_uint64 size){ ofOutput.write(data, size); return bool(ofOutput); }

Cannot link to static libraries

Hello, I have tried to use your project to link directly to functions provided by libzip. In my CMakeLists.txt file I include libraries "libzippp_static.lib", "zipstatic.lib" and "zlibstaticd.lib". I have also included the necessary include directories with header files. When I try to build the project I get errors in this form:

: error LNK2019: unresolved external symbol __imp_zip_add referenced in function ...

Can you help me solve this error?

Memory leak when zip_open_from_source failed

libzippp/src/libzippp.cpp

Lines 176 to 187 in bc9f4c5

/* open zip archive from source */
zipHandle = zip_open_from_source(source, zipFlag, &error);
if (zipHandle == nullptr) {
fprintf(stderr, "can't open zip from source: %s\n", zip_error_strerror(&error));
zip_source_free(zipSource);
zipSource = nullptr;
zip_error_fini(&error);
return false;
}
zip_error_fini(&error);
zipSource = source;

zip_source_free(zipSource);

this should be zip_source_free(source) ?

Zip file fails to open for some users

I'm using libzippp via vcpkg in my software to open a zip file and to access a certain file inside the zip. This seems to work fine for most users but for some users my code fails to open the zip file:

libzippp::ZipArchive zip_archive(zip_file_path.string());
const auto file_opened_successfully = zip_archive.open(libzippp::ZipArchive::ReadOnly);
if (!file_opened_successfully)
{
    throw std::runtime_error("Failed to open the archive file");
}

Here, the exception is thrown. I confirmed that the file referenced by zip_file_path is exactly the same one as expected so no tampering or corruption has occurred with the zip file.

  1. Is there a way to get more details on why opening the file failed?
  2. What are possible causes for an open() failure despite it working on my development machine (and my other 2 test machines)? Can it be an encoding problem of the file path, e.g. if the user comes from Asian countries and uses non-ASCII symbols in the file path? There is no constructor for std::wstring file paths or for std::filesystem::path objects. My project is compiled with the character set Use Unicode Character Set in Visual Studio. A previous call to std::filesystem::is_regular_file(zip_file_path) yields that the file exists though.

Does readEntry reads an entry completely to memory?

From reading the comments and the source code, unlike libzipp's zip_fread, apparently ZipArchive::readEntry reads and entire entry to memory. Is this true? If so, what happens if the entry is a 20GB file?

ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [libzippp-shared] Error 1

when i make project, get this error:
g++ -g -fPIC -c -Ilib/libzip-1.2.0/lib -o obj/libzippp.o -W -Wall -Wextra -ansi -pedantic -std=c++0x src/libzippp.cpp
ar rvs libzippp.a obj/libzippp.o
ar: creating archive libzippp.a
a - obj/libzippp.o
g++ -shared -o libzippp.so obj/libzippp.o
Undefined symbols for architecture x86_64:
"_zip_close", referenced from:
libzippp::ZipArchive::close() in libzippp.o
"_zip_delete", referenced from:
libzippp::ZipArchive::deleteEntry(libzippp::ZipEntry const&) const in libzippp.o
"_zip_dir_add", referenced from:
libzippp::ZipArchive::addEntry(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&) const in libzippp.o
"_zip_discard", referenced from:
libzippp::ZipArchive::discard() in libzippp.o
"_zip_fclose", referenced from:
libzippp::ZipArchive::readEntry(libzippp::ZipEntry const&, bool, libzippp::ZipArchive::State, unsigned long) const in libzippp.o
libzippp::ZipArchive::readEntry(libzippp::ZipEntry const&, std::__1::basic_ofstream<char, std::__1::char_traits >&, libzippp::ZipArchive::State, unsigned long) const in libzippp.o
"_zip_file_add", referenced from:
libzippp::ZipArchive::addFile(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&) const in libzippp.o
libzippp::ZipArchive::addData(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, void const*, unsigned long, bool) const in libzippp.o
"_zip_file_get_comment", referenced from:
libzippp::ZipArchive::getEntryComment(libzippp::ZipEntry const&, libzippp::ZipArchive::State) const in libzippp.o
"_zip_file_rename", referenced from:
libzippp::ZipArchive::renameEntry(libzippp::ZipEntry const&, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&) const in libzippp.o
"_zip_file_set_comment", referenced from:
libzippp::ZipArchive::setEntryComment(libzippp::ZipEntry const&, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&) const in libzippp.o
"_zip_fopen_index", referenced from:
libzippp::ZipArchive::readEntry(libzippp::ZipEntry const&, bool, libzippp::ZipArchive::State, unsigned long) const in libzippp.o
libzippp::ZipArchive::readEntry(libzippp::ZipEntry const&, std::__1::basic_ofstream<char, std::__1::char_traits >&, libzippp::ZipArchive::State, unsigned long) const in libzippp.o
"_zip_fread", referenced from:
libzippp::ZipArchive::readEntry(libzippp::ZipEntry const&, bool, libzippp::ZipArchive::State, unsigned long) const in libzippp.o
libzippp::ZipArchive::readEntry(libzippp::ZipEntry const&, std::__1::basic_ofstream<char, std::__1::char_traits >&, libzippp::ZipArchive::State, unsigned long) const in libzippp.o
"_zip_get_archive_comment", referenced from:
libzippp::ZipArchive::getComment(libzippp::ZipArchive::State) const in libzippp.o
"_zip_get_num_entries", referenced from:
libzippp::ZipArchive::getNbEntries(libzippp::ZipArchive::State) const in libzippp.o
"_zip_name_locate", referenced from:
libzippp::ZipArchive::hasEntry(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, bool, bool, libzippp::ZipArchive::State) const in libzippp.o
libzippp::ZipArchive::getEntry(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, bool, bool, libzippp::ZipArchive::State) const in libzippp.o
"_zip_open", referenced from:
libzippp::ZipArchive::open(libzippp::ZipArchive::OpenMode, bool) in libzippp.o
"_zip_set_archive_comment", referenced from:
libzippp::ZipArchive::setComment(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&) const in libzippp.o
"_zip_set_default_password", referenced from:
libzippp::ZipArchive::open(libzippp::ZipArchive::OpenMode, bool) in libzippp.o
"_zip_set_file_compression", referenced from:
libzippp::ZipArchive::setEntryCompressionEnabled(libzippp::ZipEntry const&, bool) const in libzippp.o
"_zip_source_buffer", referenced from:
libzippp::ZipArchive::addData(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, void const*, unsigned long, bool) const in libzippp.o
"_zip_source_file", referenced from:
libzippp::ZipArchive::addFile(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&) const in libzippp.o
"_zip_source_free", referenced from:
libzippp::ZipArchive::addFile(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&) const in libzippp.o
libzippp::ZipArchive::addData(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, void const*, unsigned long, bool) const in libzippp.o
"_zip_stat_index", referenced from:
libzippp::ZipArchive::getEntries(libzippp::ZipArchive::State) const in libzippp.o
libzippp::ZipArchive::getEntry(long, libzippp::ZipArchive::State) const in libzippp.o
"_zip_stat_init", referenced from:
libzippp::ZipArchive::getEntries(libzippp::ZipArchive::State) const in libzippp.o
libzippp::ZipArchive::getEntry(long, libzippp::ZipArchive::State) const in libzippp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [libzippp-shared] Error 1

vcpkg custom install

Hey

I'm trying to add this library to my project, but I hit a wall as .h files are not being included in my project.
I do it currently via >
include(path/to/vcpkg/scripts/buildsystems/vcpkg.cmake)
find_package(libzippp REQUIRED)
set(icZLibLib libzippp::libzippp)

Is there a ${} that I can use to retrieve both include_dirs & libs for custom includes/etc ?

TIA.

add support of zip_set_file_compression

Depending on the content of the entry it may not make sense to compress, Adding support for zip_set_file_compression will allow users to disable compression for a specific entry

libzippp::ZipArchive seems to be just support utf8 ....

Just as the title, when use libzippp to commpress some file with Chinese in path(not just ANSI) failed, through the source code i find it seems to be just support utf8....
So, I think it can wrap a transcode to support tstring... not utf8
image

Change enums to lowercase

per the isocpp/CppCoreGuidelines.

Enum.5: Don't use ALL_CAPS for enumerators

Reason

Avoid clashes with macros.

Example, bad

 // webcolors.h (third party header)
#define RED   0xFF0000
#define GREEN 0x00FF00
#define BLUE  0x0000FF

// productinfo.h
// The following define product subtypes based on color

enum class Product_info { RED, PURPLE, BLUE };   // syntax error

Enforcement

Flag ALL_CAPS enumerators.

I can imagine READ_ONLY and WRITE being macros in the embedded world.

How to extract non-English file name?

I failed to extract non-English file name, even if I replace zip_open with windows_open from libzip's example.
Environment: Win10 + VS2015 + zip archived by 7zip.
Do you know how to do that?

ZipArchive::fromBuffer shouldn't return a pointer that should be deleted by the user

static ZipArchive* fromBuffer(void* buffer, libzippp_uint32 size, OpenMode mode=ReadOnly, bool checkConsistency=false);

By returning a pointer created from new (and requiring users to use delete on it), it would be really easy to let users call delete across DLL boundaries, which might cause issues.
There are plenty of questions about it on StackOverflow, for example: https://stackoverflow.com/questions/443147/c-mix-new-delete-between-libs

I suggest to provide a static void ZipArchive::free(ZipArchive*) function, which calls delete from libzippp's translation unit, and require users to call this function (instead of calling delete inside their own translation unit) for any ZipArchive pointers returned from this library (for example returned by ZipArchive::fromBuffer).
We could even provide a smart pointer:

// inside libzippp.h
class ZipArchive;

struct ZipArchiveDeleter {
    void operator()(ZipArchive* p) const noexcept;
};
using ZipArchivePointer = std::unique_ptr<ZipArchive, ZipArchiveDeleter>;

class LIBZIPPP_API ZipArchive {
public:
    // implementation should be inside libzippp's translation unit
    static void ZipArchive::free(ZipArchive* p) noexcept;
    // old version, users should be advised to use ZipArchive::free() instead of operator delete
    static ZipArchive* fromBuffer(...);
    // new version, which is also safer because it uses smart pointer
    static ZipArchivePointer fromBuffer(...);
}

// inside libzippp.cpp
void ZipArchive::free(ZipArchive* p) noexcept {
    delete p;
}
void ZipArchiveDeleter::operator()(ZipArchive* p) const noexcept {
    ZipArchive::free(p);
}

Consider Licensing under a common license

Hi, thanks for this wrapper around libzip :D

I was wondering if you would consider relicensing this under a common license (eg. MIT, BSD3 etc). This usually makes the process of allowing to use your library easier in work environments.

Thanks again :)

Unable to use libzip pkgcfg to find include and lib directories and unsuccessful install using vcpkg

I am attempting to use CMake GUI to compile libzippp static to statically link to libzip and zlib both of which seem to be working smoothly and have downloaded successfully using vcpkg. Attempting to compile using the version distributed vcpkg (libzippp:x86-windows-static) leads to these compilation errors:

ExtractZip.obj : error LNK2019: unresolved external symbol "public: long __thiscall libzippp::ZipArchive::getNbEntries(enum libzippp::ZipArchive::State)const " (?getNbEntries@ZipArchive@libzippp@@QBEJW4State@12@@Z) referenced

and

ExtractZip.obj : error LNK2019: unresolved external symbol "public: int __thiscall libzippp::ZipEntry::readContent(class std::basic_ostream<char,struct std::char_traits<char> > &,enum libzippp::ZipArchive::State,unsigned long)const " (?readContent@ZipEntry@libzippp@@QBEHAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@W4State@ZipArchive@2@K@Z) referenced

So as a result of this I decided to try and link to the already compiled libzip and compile libzippp manually using CMake and VS2019, however I cannot generate the solution as I get this error when trying to use the libzip pkgcfg which I believe is located at lib/pkgconfig/zip.pc and I get this error:

CMake Error at C:/Program Files/CMake/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
  Could NOT find LIBZIP (missing: LIBZIP_LIBRARY LIBZIP_INCLUDE_DIR)
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:458 (_FPHSA_FAILURE_MESSAGE)
  cmake/FindLIBZIP.cmake:17 (find_package_handle_standard_args)
  CMakeLists.txt:20 (find_package)

I'm trying to build for Win32, x86, using CMake 3.18.0 and VS2019.

Thank you for any help.

ZipArchive's buffer length's type is too small

bufferLength is of type libzippp_uint32 but gets libzippp_uint64 values assigned. So, either the assigned values have to be checked that they are smaller than 2^32-1 and then explicitly casted or the bufferLength has to be of type libzippp_uint64.

Failed to link static lib in VS2015

Does the pre-compiled lib compatible with VS2015? I got link errors:

Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: bool __thiscall libzippp::ZipArchive::open(enum libzippp::ZipArchive::OpenMode,bool)" (_imp?open@ZipArchive@libzippp@@QAE_NW4OpenMode@12@_N@Z) referenced in function "public: void __thiscall UnitTest::ZipTest::ShouldUnzip(void)" (?ShouldUnzip@ZipTest@UnitTest@@QAEXXZ) UnitTest C:\Users\xxx\Documents\Visual_Studio_2015\Projects\UnitTest\ZipTest.obj 1
Error LNK1120 3 unresolved externals UnitTest C:\Users\ruigao\Documents\Visual_Studio_2015\Projects\ShiPanE\Debug\UnitTest.dll 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: virtual __thiscall libzippp::ZipArchive::~ZipArchive(void)" (_imp??1ZipArchive@libzippp@@UAE@XZ) referenced in function "public: void __thiscall UnitTest::ZipTest::ShouldUnzip(void)" (?ShouldUnzip@ZipTest@UnitTest@@QAEXXZ) UnitTest C:\Users\ruigao\Documents\Visual_Studio_2015\Projects\UnitTest\ZipTest.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall libzippp::ZipArchive::ZipArchive(class std::basic_string<char,struct std::char_traits,class std::allocator > const &,class std::basic_string<char,struct std::char_traits,class std::allocator > const &)" (_imp??0ZipArchive@libzippp@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@0@Z) referenced in function "public: void __thiscall UnitTest::ZipTest::ShouldUnzip(void)" (?ShouldUnzip@ZipTest@UnitTest@@QAEXXZ) UnitTest C:\Users\ruigao\Documents\Visual_Studio_2015\Projects\UnitTest\ZipTest.obj 1

Interesting thing is I could link successfully with (libzippp.lib), but unable to run the application.

"make" command as per the README is failing

I am getting this error, when I perform a 'make'. But the step 2 - 'make libraries' is working perfectly fine.

Any suggestions? What is with the architecture error? Isn't this supported for x86_64 arch?

202 warnings generated. ar rvs libzippp.a obj/libzippp.o r - obj/libzippp.o c++ -shared -o libzippp.so obj/libzippp.o Undefined symbols for architecture x86_64: "_zip_close", referenced from: libzippp::ZipArchive::close() in libzippp.o "_zip_delete", referenced from: libzippp::ZipArchive::deleteEntry(libzippp::ZipEntry const&) const in libzippp.o "_zip_dir_add", referenced from: libzippp::ZipArchive::addEntry(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const in libzippp.o "_zip_discard", referenced from: libzippp::ZipArchive::discard() in libzippp.o "_zip_fclose", referenced from: libzippp::ZipArchive::readEntry(libzippp::ZipEntry const&, bool, libzippp::ZipArchive::State, unsigned long) const in libzippp.o libzippp::ZipArchive::readEntry(libzippp::ZipEntry const&, std::__1::basic_ofstream<char, std::__1::char_traits<char> >&, libzippp::ZipArchive::State, unsigned long) const in libzippp.o "_zip_file_add", referenced from: libzippp::ZipArchive::addFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const in libzippp.o libzippp::ZipArchive::addData(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, void const*, unsigned long, bool) const in libzippp.o "_zip_file_get_comment", referenced from: libzippp::ZipArchive::getEntryComment(libzippp::ZipEntry const&, libzippp::ZipArchive::State) const in libzippp.o "_zip_file_rename", referenced from: libzippp::ZipArchive::renameEntry(libzippp::ZipEntry const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const in libzippp.o "_zip_file_set_comment", referenced from: libzippp::ZipArchive::setEntryComment(libzippp::ZipEntry const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const in libzippp.o "_zip_fopen_index", referenced from: libzippp::ZipArchive::readEntry(libzippp::ZipEntry const&, bool, libzippp::ZipArchive::State, unsigned long) const in libzippp.o libzippp::ZipArchive::readEntry(libzippp::ZipEntry const&, std::__1::basic_ofstream<char, std::__1::char_traits<char> >&, libzippp::ZipArchive::State, unsigned long) const in libzippp.o "_zip_fread", referenced from: libzippp::ZipArchive::readEntry(libzippp::ZipEntry const&, bool, libzippp::ZipArchive::State, unsigned long) const in libzippp.o libzippp::ZipArchive::readEntry(libzippp::ZipEntry const&, std::__1::basic_ofstream<char, std::__1::char_traits<char> >&, libzippp::ZipArchive::State, unsigned long) const in libzippp.o "_zip_get_archive_comment", referenced from: libzippp::ZipArchive::getComment(libzippp::ZipArchive::State) const in libzippp.o "_zip_get_num_entries", referenced from: libzippp::ZipArchive::getNbEntries(libzippp::ZipArchive::State) const in libzippp.o "_zip_name_locate", referenced from: libzippp::ZipArchive::hasEntry(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, bool, libzippp::ZipArchive::State) const in libzippp.o libzippp::ZipArchive::getEntry(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, bool, libzippp::ZipArchive::State) const in libzippp.o "_zip_open", referenced from: libzippp::ZipArchive::open(libzippp::ZipArchive::OpenMode, bool) in libzippp.o "_zip_set_archive_comment", referenced from: libzippp::ZipArchive::setComment(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const in libzippp.o "_zip_set_default_password", referenced from: libzippp::ZipArchive::open(libzippp::ZipArchive::OpenMode, bool) in libzippp.o "_zip_set_file_compression", referenced from: libzippp::ZipArchive::setEntryCompressionEnabled(libzippp::ZipEntry const&, bool) const in libzippp.o "_zip_source_buffer", referenced from: libzippp::ZipArchive::addData(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, void const*, unsigned long, bool) const in libzippp.o "_zip_source_file", referenced from: libzippp::ZipArchive::addFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const in libzippp.o "_zip_source_free", referenced from: libzippp::ZipArchive::addFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const in libzippp.o libzippp::ZipArchive::addData(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, void const*, unsigned long, bool) const in libzippp.o "_zip_stat_index", referenced from: libzippp::ZipArchive::getEntries(libzippp::ZipArchive::State) const in libzippp.o libzippp::ZipArchive::getEntry(long, libzippp::ZipArchive::State) const in libzippp.o "_zip_stat_init", referenced from: libzippp::ZipArchive::getEntries(libzippp::ZipArchive::State) const in libzippp.o libzippp::ZipArchive::getEntry(long, libzippp::ZipArchive::State) const in libzippp.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [libzippp-shared] Error 1

Missing test.zip

When building libzip with cmake the following test fails with:
test_shared: tests/tests.cpp:64: void test1(): Assertion z2.isOpen()' failed.`

The zip_strerror(zipHandle) from libzip is: Seek error: Value too large for defined data type after zip_close(zipHandle) had returned -1

Attached you find a patch to reproduce the problem on Linux. I've removed the static test because the cmake build doesn't build it by default.

After patch do: make libzip && make && make tests

"make libraries" not working on Mac OS

I'm working on a C++ project that will later be a Web Assembly module to use with JavaScript, not relevant but useful to know where i intend to go with this.

Click here to go to my GitHub project

When i clone/run the project I'm getting the error:

[ 87%] Building C object lib/CMakeFiles/zip.dir/zip_mkstempm.c.o
make[3]: *** No rule to make target `/Users/alejandrocamba/Documents/libzippp/lib/zlib-1.2.11/libz.so', needed by `lib/libzip.5.3.dylib'.  Stop.
make[3]: *** Waiting for unfinished jobs....
[ 87%] Building C object lib/CMakeFiles/zip.dir/zip_source_file_stdio_named.c.o
[ 87%] Building C object lib/CMakeFiles/zip.dir/zip_random_unix.c.o
make[2]: *** [lib/CMakeFiles/zip.dir/all] Error 2
make[1]: *** [all] Error 2
make: *** [libzip-build-shared] Error 2

I'm using Visual Studio Code and the editor config for c++ files is:

            "includePath": [
                "${workspaceFolder}/**",
                "/usr/local/Cellar/opencv/4.3.0_5/include/opencv4",
                "/Users/alejandrocamba/Documents/leptonica/build/",
                "/Users/alejandrocamba/Documents/tesseract/build/",
                "/usr/local/Cellar/libzip/1.7.3/",
                "/usr/local/Cellar/zlib/1.2.11/",
                "/usr/local/include/libzippp"
            ]

I tried the following workaround based on some online solutions i found:

mkdir build && cd build
cmake ..

-- The C compiler identification is AppleClang 11.0.0.11000033
-- The CXX compiler identification is AppleClang 11.0.0.11000033
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found ZLIB: /usr/lib/libz.dylib (found version "1.2.11")
-- Found LIBZIP: /usr/local/lib/libzip.dylib
-- Found BZip2: /usr/lib/libbz2.dylib (found version "1.0.6")
-- Looking for BZ2_bzCompressInit
-- Looking for BZ2_bzCompressInit - found
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/alejandrocamba/Documents/libzippp/build

make

Scanning dependencies of target libzippp
[ 25%] Building CXX object CMakeFiles/libzippp.dir/src/libzippp.cpp.o
[ 50%] Linking CXX static library libzippp_static.a
[ 50%] Built target libzippp
Scanning dependencies of target libzippp_test
[ 75%] Building CXX object CMakeFiles/libzippp_test.dir/tests/tests.cpp.o
[100%] Linking CXX executable libzippp_static_test
[100%] Built target libzippp_test

make install

[ 50%] Built target libzippp
[100%] Built target libzippp_test
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/lib/libzippp_static.a
-- Up-to-date: /usr/local/include/libzippp/libzippp.h
-- Installing: /usr/local/share/libzippp/libzipppConfig.cmake
-- Installing: /usr/local/share/libzippp/libzipppConfigVersion.cmake
-- Up-to-date: /usr/local/share/libzippp/FindLIBZIP.cmake
-- Installing: /usr/local/share/libzippp/libzipppTargets.cmake
-- Installing: /usr/local/share/libzippp/libzipppTargets-noconfig.cmake

My CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 2.8)
project(startProject)
set(Leptonica_DIR /Users/alejandrocamba/Documents/leptonica/build)

list(APPEND CMAKE_PREFIX_PATH "/Users/alejandrocamba/Documents/libzippp/lib/libzip-1.7.1/")
list(APPEND CMAKE_PREFIX_PATH "/Users/alejandrocamba/Documents/libzippp/lib/zlib-1.2.11/")

find_package(OpenCV REQUIRED)
find_package(Leptonica REQUIRED)
find_package(Tesseract REQUIRED)
find_package(libzippp 3.0 REQUIRED)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(${Leptonica_INCLUDE_DIRS})
include_directories(${Tesseract_INCLUDE_DIRS})

add_executable(startProject main.cpp)
target_link_libraries(startProject PRIVATE libzippp::libzippp)
target_link_libraries(startProject ${OpenCV_LIBS})
target_link_libraries(startProject ${Tesseract_LIBRARIES})

I'm able to import the library but when i try tu run the project i finally get the error:

(/project) make

[ 50%] Building CXX object CMakeFiles/startProject.dir/main.cpp.o
[100%] Linking CXX executable startProject
ld: library not found for -llibzip::libzip
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [startProject] Error 1
make[1]: *** [CMakeFiles/startProject.dir/all] Error 2
make: *** [all] Error 2

I've tried other other solutions i've found on the internet but i can't find a way to install libzip from the repo either, when i go to libzippp/lib/libzip-1.7.1/build and run make install i get

make[2]: *** No rule to make target `/Users/alejandrocamba/Documents/libzippp/lib/zlib-1.2.11/libz.so', needed by `lib/libzip.5.3.dylib'.  Stop.
make[1]: *** [lib/CMakeFiles/zip.dir/all] Error 2
make: *** [all] Error 2

Allow usage as sub-project

I suggest to support use cases using this as a git submodule and via cmake add_subdirectory

Changes required that I've seen:

  • Conditionally enable test/install if top-level project:
    option(INSTALL_HEADERS "Install library headers" ON)
    (CMAKE_SOURCE_DIR vs PROJECT_SOURCE_DIR)
  • Decide on include method. You seem to prefer #include <libzippp.h>? Often a subfolder is used: #include <libzippp/libzipp.h> This allows adding more headers later without clobbering the includes. Example: libzippp/config.h which is impossible with having the subfolder in the include path. Relevant code: https://github.com/ctabin/libzippp/blob/master/CMakeLists.txt#L18-L19
  • Don't make LIBZIPPP_EXPORTS public:
    target_compile_definitions(libzippp PUBLIC LIBZIPPP_EXPORTS)
  • allow disabling install of anything like (see also first point)
    if (INSTALL_HEADERS)
  • add alias target libzippp::libzippp (same as installed name, so either can be used)

BTW: Nice modern CMake! ๐Ÿ‘

Signed/unsigned mismatch on ZipEntry

In Visual Studio we see the following compiler error when running with /WX which treats all warnings as errors:

libzippp.h(550): warning C4245: 'initializing': conversion from 'int' to 'libzippp_uint16', signed/unsigned mismatch

Using MSVC version 14.29.30132. The following command line is used for the debug build:

cl.exe /nologo /TP -Ilibzippp\src -Izlib\include /DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd /permissive- /utf-8 /W4 /WX -std:c++17 /FS -c <file>.cpp

At the moment, using static_cast works around the issue by mapping to an undefined compression method and ZIP_EM_UNKNOWN encryption method respectively.

Original:

        explicit ZipEntry(void) : zipFile(nullptr), index(0), time(0), compressionMethod(-1), encryptionMethod(-1), size(0), sizeComp(0), crc(0) {}

Workaround:

        explicit ZipEntry(void) : zipFile(nullptr), index(0), time(0), compressionMethod(static_cast<libzippp_uint16>(-1)), encryptionMethod(static_cast<libzippp_uint16>(-1)), size(0), sizeComp(0), crc(0) {}

Unresolved external symbols with MSVC 2013

Hi, i did built the library succesfully with MSVC 2013 and i now link against libzippp_static.lib and get the following linker errors:
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_close
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_delete
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_dir_add
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_discard
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_fclose
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_file_add
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_file_get_comment
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_file_rename
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_file_set_comment
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_fopen_index
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_fread
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_get_archive_comment
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_get_num_entries
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_name_locate
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_open
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_set_archive_comment
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_set_default_password
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_source_buffer
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_source_file
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_source_free
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_stat_index
1>libzippp_static.lib(libzippp.obj) : error LNK2001: unresolved external symbol _zip_stat_init

Is this an issue on my side or a bug?

compiled libary

can you please share pre-compiled library of libzipp please .a lib for windows will be appreciated

Extract to the folder

Hey!
I've saw #23 issue, and trying to adapt code for myself, this works on macos, but completely not working on windows.
What I mean I have "deios.zip"
With next hierarchy:
deios.zip
- deios (folder)
- shaders (folder)
- dx11 (folder)
- files..
- opengl
- files...
- assets
- bundles (folder)
- files..

  1. First Im confused that its not recognized deios root folder as folder.
  2. if (entry.isDirectory() || uSize == 0 && uCRC == 0) point ONLY at deios\shaders\ and deios\assets\bundles.
    Everything else it counts as file.

Code to unzip:


bool extract_files_from_zip(std::string target_dir, const std::string& zip_file)
{
    bool res = false;
    int u_count = 0;

    std::filesystem::remove_all(target_dir + "deios");
    std::filesystem::create_directory(target_dir + "deios");

    if (target_dir.at(target_dir.size() - 1) != '/' && target_dir.at(target_dir.size() - 1) != '\\')
    {
        if (target_dir.find_first_of('/') != std::string::npos)
            target_dir.append("/");
        else
            target_dir.append("\\");
    }

    libzippp::ZipArchive zf(zip_file);
    if (!zf.open(libzippp::ZipArchive::ReadOnly))
        return false; // Zip file couldn't be opened !

    std::vector<libzippp::ZipEntry> entries = zf.getEntries();
    std::vector<libzippp::ZipEntry>::iterator it;
    libzippp::ZipEntry entry;

    // Determine the size (uncompressed) of all the zip entries to send it to the progress callback
    size_t uTotSize = 0;
    size_t uWrittenBytes = 0;
    for (it = entries.begin(); it != entries.end(); ++it)
    {
        entry = *it;
        if (entry.isFile())
            uTotSize += entry.getSize();
    }

    // Creating directories
    for (it = entries.begin(); it != entries.end(); ++it)
    {
        entry = *it;
        std::string strEntryName = entry.getName();
        size_t uSize = entry.getSize();
        size_t uCRC = entry.getCRC();

        // in rare cases, a directory might be coded incorrectly in a zip file : no '/' is appended at the
        // end of its name, that's why I check uCRC and uSize...
        if (entry.isDirectory() || uSize == 0 && uCRC == 0)
        {
            if (!std::filesystem::create_directories(target_dir + strEntryName))
            {
                spdlog::error("Can't create directory: {}", target_dir + strEntryName);
                //                return false;
            }

            ++u_count;
        }
    }

    // Creating files
    for (it = entries.begin(); it != entries.end(); ++it)
    {
        entry = *it;
        std::string strEntryName = entry.getName();
        size_t uSize = entry.getSize();
        size_t uCRC = entry.getCRC();

        if (entry.isFile()) // // Extract Zip entry to a file.
        {
            // to avoid copying a huge zip entry to main memory and causing a memory allocation failure
            // a buffer will be used instead !
            std::ofstream ofUnzippedFile(target_dir + strEntryName, std::ofstream::binary);
            if (ofUnzippedFile)
            {
                if (entry.readContent(ofUnzippedFile, libzippp::ZipArchive::Current) == 0)
                {
                    uWrittenBytes += uSize;
                    ++u_count;
                }
                else
                {
                    spdlog::error("Can't write into: {}", target_dir + strEntryName);
                    continue;
                }
            }
            else
                spdlog::error("Can't create file: {}", target_dir + strEntryName);

            ofUnzippedFile.close();
        }
    }

    res = (zf.getNbEntries() == static_cast<long>(u_count));
    zf.close();

    return res;
}

Could NOT find LIBZIP (missing: _libzip_pkgcfg)

Error:

CMake Error at /usr/local/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find LIBZIP (missing: _libzip_pkgcfg)
Call Stack (most recent call first):
  /usr/local/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  cmake/FindLIBZIP.cmake:17 (find_package_handle_standard_args)
  CMakeLists.txt:20 (find_package)

libzip-1.7.3 provides its own cmake files that should be used. I solved this with this patch:

+++ CMakeLists.txt
@@ -17,7 +17,7 @@ option(LIBZIPPP_ENABLE_ENCRYPTION "Build with encrypti
 
 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
 
-find_package(LIBZIP MODULE REQUIRED)
+find_package(libzip REQUIRED)
 
 add_library(libzippp "src/libzippp.cpp")
 add_library(libzippp::libzippp ALIAS libzippp) # Convenience alias
@@ -87,10 +87,10 @@ if(LIBZIPPP_INSTALL)
     COMPATIBILITY SameMajorVersion
   )
 
-  install(
-    FILES ${PROJECT_CONFIG_FILE} ${PROJECT_VERSION_FILE} cmake/FindLIBZIP.cmake
-    DESTINATION ${configInstallDestination}
-  )
+  #install(
+  #  FILES ${PROJECT_CONFIG_FILE} ${PROJECT_VERSION_FILE} cmake/FindLIBZIP.cmake
+  #  DESTINATION ${configInstallDestination}
+  #)
 
   install(
     EXPORT libzipppTargets

OS: FreeBSD 13

Incorrect CMake target referenced in README

The README suggests to use the imported target libzipp::libzipp when using libzippp in your own CMake project. This is incorrect and results in build errors, as the imported target is actually libzippp::libzippp.

allocation check

Great job, adopted !

Just a note, you should check if allocation is successful, line 271
char* data = new char[isize+(asText ? 1 : 0)];
if(data){ ...

This is important if for example this code is used on a server with limited resources

IS_DIRECTORY cannot deal with delimiter on windows('\\")

Just like the title, because windows delimiter is '\', but the macro DIRECTORY_SEPARATOR is defined as '/'
Follow is the code:
#define DIRECTORY_SEPARATOR '/'
#define IS_DIRECTORY(str) ((str).length()>0 && (str)[(str).length()-1]==DIRECTORY_SEPARATOR)
#define DEFAULT_CHUNK_SIZE 524288

And why not provide a interface just lik addDir that add all the file&directory in a directory to an entry

And more ...
I cannot find a interface that can uncompress a compressed file( like test.zip) to a directory...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.