Search code examples
c++clibzip

Libzip zip_dir_add from manual not declared - C/C++


I am quite new to C/C++ programming so please take that into account.

Problem :

When using the libzip library, some of the functions descibed on the manual are said to be not declared in the scope when compiling. I read this tutorial (in french sorry) which was written in 2011. It uses different function names (zip_dir_add is zip_add_dir etc..)

I think that might be due to the installation process. Or maybe I forgot to include some files..

Here is what i have done so far :

1)installing the libzip library using ubuntu packages like this :

sudo apt-get install libzip-dev libzip2

2) trying it on simple code

#include <iostream>
#include <zip.h>

using namespace std;

int main()
{
  struct zip *zip;
  int err(0);

  zip = zip_open("testzip.zip", ZIP_CREATE, &err);
  zip_dir_add(zip, "upld");
  zip_close(zip);

  return 0;
}

This returns : zip_dir_add was not declared in this scope

Any idea what could cause that ?

Thanks in advance !


Solution

  • Your question has 2 parts, 1 why zip_dir_add is not being compiled, while the documentation suggests to use zip_dir_add as zip_add_dir is obsolete. The answer is you might be referring to a different version of code and different version of documentation. To cross verify go to the include path of libZip and open zip.h and check zip_dir_add, which you would not find.

    The second question is why, zip_add_dir is creating an empty archive file. The answer is when you add a directory to zip_add_dir, it does NOT automatically add all the files (underneath the directory) to the archive, you have to walk-through the directory and add individual files using zip_add.