1

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 !

M0rkHaV
  • 432
  • 1
  • 4
  • 16

3 Answers3

2

You wrote it yourself: zip_dir_add actually should be zip_add_dir - or did I misunderstand?

EDIT: just had a quick look at the lib - indeed there exists zip_dir_add, but it's internal. The externally declared wrapper is zip_add_dir.

EDIT2: After another look, this time into <zip.h>. There, zip_add_dir is marked as "deprecated" and zip_dir_add seems to be the way to go.

I fear that your compiler tries to include zlib's zip.h and not yours.

As you are on linux (obviously) I'd recommend to switch to some lib that is more widespread, like mentioned zlib (which includes minizip, and that is most likely what you need). Read on here!

Community
  • 1
  • 1
St0fF
  • 1,553
  • 12
  • 22
  • thanks for your answer. Could you please tell me the difference between internal and external ? Does internal tands for the functions used inside the library to make it work and external for the functions the end user should use ? In that case, where can i find a user documentation ? – M0rkHaV Sep 25 '14 at 10:24
  • @PVC: Yes that's right. As for documentation, you linked to it in your question. – Lightness Races in Orbit Sep 25 '14 at 13:54
  • Thanks for answering. I know i put it but as said, there is no mention of zip_add_dir in the doc. I ll try to work it out with my other link. Thanks ! (I am sorry i cannot upvote your answers, i dont have enough reputation yet) – M0rkHaV Sep 26 '14 at 08:28
  • Look at my next edit above. If you can't vote up, you still can make an answer "accepted" by clicking that nice hook so it turns green :) – St0fF Sep 26 '14 at 21:58
  • Sorry, i have just seen your comment and edit. How can i check if it is the right zip.h that is called ? I know i could switch to another library but i was asked to work with this one. If there is no other possibility i ll change but i'd rather not. I checked and the version i am using is the 0.10 and not the 0.11. I tried to install the 0.11 from the tar provided on the libzip website but could not manage to do it... If i remove the packages there is always something missing and if i keep those, the 0.11 version is not used.I click the hook when i've an answer not if told to do smthg else :P – M0rkHaV Oct 07 '14 at 15:24
  • 1
    if your "special" zip library is in your source path, you should use `#include "relative_path_to/zip.h"` - using double-quotes makes the preprocessor search relative to the current file's location. Using brackets makes the preprocessor scan the include-directories for the file. – St0fF Oct 08 '14 at 11:48
  • On the other hand: if that libzip-dev you installed really is "your libzip", you should search for the right zip.h-file and give a path relative to your system's include directory within the brackets. Using a good ide will most likely offer auto-completion for that. – St0fF Oct 08 '14 at 11:50
2

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.

Sandeep
  • 1,237
  • 1
  • 14
  • 29
  • You are right. As the version of libzip in the ubuntu packages does not correspond to the latest one. As i did not want to go throw the whole process of downloading and compiling the latest version of the library, i used the old one and it works fine finally. Thanks ! – M0rkHaV Dec 05 '14 at 08:29
1

Function is int zip_add_dir(); Try it. It should work.

wilx
  • 17,697
  • 6
  • 59
  • 114
Tejas Pawar
  • 690
  • 8
  • 16
  • I did try it but it doesnot work. The zip archive is created but it is empty in the archive manager given with ubuntu.. – M0rkHaV Sep 25 '14 at 10:21
  • I am facing exactly the same issue. Unfortunately I cannot use zip_dir_add as it is introduced in the latest version and I cannot upgrade, hence has to use zip_add_dir. But end result is, it creates zip file but with no content in it. Any pointers? – Sandeep Dec 04 '14 at 07:58
  • If you want i can give you the code i use. It is fairly simple once you understand the different functions needed. – M0rkHaV Dec 05 '14 at 08:32