First of all allow me some comments:

Your program is not compiled and linked by Eclipse.

Compiling is done by the compiler (gcc using option -c):

make all 
Building file: ../zip.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"zip.d" -MT"zip.d" -o "zip.o" "../zip.c"
Finished building: ../zip.c

Linking is done by the linker (via the compiler using option -o):

Invoking: GCC C Linker
gcc  -o "unzipper"  ./zip.o   
./main.o: In function `zip':
/home/alk/workspace/unzipper/Debug/../zip.c:20: undefined reference to `zip_open'
/home/alk/workspace/unzipper/Debug/../zip.c:27: undefined reference to `zip_get_num_files'
/home/alk/workspace/unzipper/Debug/../zip.c:33: undefined reference to `zip_fopen_index'
/home/alk/workspace/unzipper/Debug/../zip.c:35: undefined reference to `zip_fread'
/home/alk/workspace/unzipper/Debug/../zip.c:38: undefined reference to `zip_fclose'
/home/alk/workspace/unzipper/Debug/../zip.c:43: undefined reference to `zip_close'
collect2: ld returned 1 exit status

Eclipse provides a framework helping you in managing all sources and their references as also spawing compiler and linker tasks and setting their options.

When the linker told you there where undefined references to the zip_*function during the build of your program, the cause for this was, you were missing to tell the linker (via the compiler, via Eclipse) where those zip_* functions could be found.

Those zip_* functions are located in a library, namely libzip.

So what you as the programmer need to tell the linker (via the compiler, via Eclipse) is to link those functions against what the compiler compiled from your sources.

As the result the linker is able to create a runnable program from your compiled sources together with all libraries needed. Certain libraries are know to Eclipse (and therfore to the linker) by default, for example the one containing the C standard functions, namely libc.

To get things going:

1 Remove the source files you pulled from the libzip librarie's sources from your project. Those sources had been compiled into the library libzip, which you will use in your project.

2 Tell the linker (via Eclipse) to use libzip for your project.

Do so by following the steps below:

open the project's properties

click 'C/C++ General'

click 'Path and Symbols', on the left select the 'Libraries' tab, there click 'Add' and enter zip

finally click 'OK'

3 Then try to build your program:

Building target: unzipper
Invoking: GCC C Linker
gcc  -o "unzipper"  ./zip.o   -lzip
Finished building target: unzipper

(Please note additional option -lzip!)

If the developement version of 'libzip' had been installed properly before, you should be fine.


PS: unzipper was the name I used for the Eclispe project to produce the examples.

PSS: I used Eclipse Juno SR1

Answer from alk on Stack Overflow
Top answer
1 of 1
3

First of all allow me some comments:

Your program is not compiled and linked by Eclipse.

Compiling is done by the compiler (gcc using option -c):

make all 
Building file: ../zip.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"zip.d" -MT"zip.d" -o "zip.o" "../zip.c"
Finished building: ../zip.c

Linking is done by the linker (via the compiler using option -o):

Invoking: GCC C Linker
gcc  -o "unzipper"  ./zip.o   
./main.o: In function `zip':
/home/alk/workspace/unzipper/Debug/../zip.c:20: undefined reference to `zip_open'
/home/alk/workspace/unzipper/Debug/../zip.c:27: undefined reference to `zip_get_num_files'
/home/alk/workspace/unzipper/Debug/../zip.c:33: undefined reference to `zip_fopen_index'
/home/alk/workspace/unzipper/Debug/../zip.c:35: undefined reference to `zip_fread'
/home/alk/workspace/unzipper/Debug/../zip.c:38: undefined reference to `zip_fclose'
/home/alk/workspace/unzipper/Debug/../zip.c:43: undefined reference to `zip_close'
collect2: ld returned 1 exit status

Eclipse provides a framework helping you in managing all sources and their references as also spawing compiler and linker tasks and setting their options.

When the linker told you there where undefined references to the zip_*function during the build of your program, the cause for this was, you were missing to tell the linker (via the compiler, via Eclipse) where those zip_* functions could be found.

Those zip_* functions are located in a library, namely libzip.

So what you as the programmer need to tell the linker (via the compiler, via Eclipse) is to link those functions against what the compiler compiled from your sources.

As the result the linker is able to create a runnable program from your compiled sources together with all libraries needed. Certain libraries are know to Eclipse (and therfore to the linker) by default, for example the one containing the C standard functions, namely libc.

To get things going:

1 Remove the source files you pulled from the libzip librarie's sources from your project. Those sources had been compiled into the library libzip, which you will use in your project.

2 Tell the linker (via Eclipse) to use libzip for your project.

Do so by following the steps below:

open the project's properties

click 'C/C++ General'

click 'Path and Symbols', on the left select the 'Libraries' tab, there click 'Add' and enter zip

finally click 'OK'

3 Then try to build your program:

Building target: unzipper
Invoking: GCC C Linker
gcc  -o "unzipper"  ./zip.o   -lzip
Finished building target: unzipper

(Please note additional option -lzip!)

If the developement version of 'libzip' had been installed properly before, you should be fine.


PS: unzipper was the name I used for the Eclispe project to produce the examples.

PSS: I used Eclipse Juno SR1

🌐
GitHub
github.com › nih-at › libzip › issues › 76
How to build both static and shared libs? · Issue #76 · nih-at/libzip
December 28, 2018 - CMakeFiles/zipcmp.dir/zipcmp.c.o: In function `test_file': zipcmp.c:(.text+0x34): undefined reference to `zip_fopen_index' zipcmp.c:(.text+0x7d): undefined reference to `zip_fread' zipcmp.c:(.text+0x91): undefined reference to `zip_fclose' zipcmp.c:(.text+0x127): undefined reference to `zip_file_strerror' zipcmp.c:(.text+0x151): undefined reference to `zip_fclose' zipcmp.c:(.text+0x163): undefined reference to `zip_strerror' CMakeFiles/zipcmp.dir/zipcmp.c.o: In function `compare_zip': zipcmp.c:(.text+0xa60): undefined reference to `zip_open' zipcmp.c:(.text+0xa7f): undefined reference to `zip_
Author   nih-at
Discussions

Compilation issue concerning zip
I have been compiling osrm on 3 different systems and I consistently receive this notice. I tried to track it down and best I can come up with I am having a linking issue with the zip.h and definit... More on github.com
🌐 github.com
21
May 24, 2012
c++ - Odd undefined reference errors - Stack Overflow
Alright I will try to describe my problem in detail. I've started using a ziploading API for SFML in order to read game resources from an archive, I've placed all required headers and source files ... More on stackoverflow.com
🌐 stackoverflow.com
October 5, 2013
QuaZip - Undefined Reference
Hey! I have a problem when I want to add QuaZip to my project. I get 100 "undefined reference" errors, which is a result of a linking problem iirc. include(u... More on forum.qt.io
🌐 forum.qt.io
32
0
June 7, 2020
c++ - Error with zip_open from libzip - Stack Overflow
I am learning C++, and I decided to make a little program that zip/unzip files to train me. I downloaded libzip and zlib and linked them to my compiler (MinGW with Code::Blocks on Windows). So I tr... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Blogger
braziebrazie.blogspot.com › 2012 › 09 › c-unzip-one-file-with-libzip.html
c - Unzip one file with libzip -
October 12, 2017 - invoking: gcc c linker gcc -o "unzipper" ./zip.o ./main.o: in function `zip': /home/alk/workspace/unzipper/debug/../zip.c:20: undefined reference `zip_open' /home/alk/workspace/unzipper/debug/../zip.c:27: undefined reference `zip_get_num_files' /home/alk/workspace/unzipper/debug/../zip.c:33: undefined reference `zip_fopen_index' /home/alk/workspace/unzipper/debug/../zip.c:35: undefined reference `zip_fread' /home/alk/workspace/unzipper/debug/../zip.c:38: undefined reference `zip_fclose' /home/alk/workspace/unzipper/debug/../zip.c:43: undefined reference `zip_close' collect2: ld returned 1 exit status
🌐
GitHub
github.com › Project-OSRM › osrm-backend › issues › 274
Compilation issue concerning zip · Issue #274 · Project-OSRM/osrm-backend
May 24, 2012 - I have been compiling osrm on 3 different systems and I consistently receive this notice. I tried to track it down and best I can come up with I am having a linking issue with the zip.h and definitions. Zip and all dependencies are insta...
Author   Project-OSRM
🌐
Libzip
libzip.org › documentation
Documentation · libzip
zip_fread — read from file · zip_fseek — seek in file · zip_ftell — tell position in file · zip_get_archive_comment — get zip archive comment · zip_get_archive_flag — get status flags for zip · zip_get_error — get zip error for archive · zip_get_file_comment — get comment for file in zip (obsolete interface) zip_get_name — get name of file by index ·
🌐
Libzip
libzip.org › documentation › zip_fseek.html
zip_fseek · libzip
libzip(3), zip_fclose(3), zip_file_get_error(3), zip_fopen(3), zip_fread(3), zip_ftell(3)
🌐
PHP
bugs.php.net › bug.php
PHP :: Bug #71655 :: Fails when compiling Zip Modules
February 23, 2016 - go to bug id or search bugs for · Before you report a bug, please make sure you have completed the following steps:
Find elsewhere
🌐
Libzip
libzip.org › documentation › zip_fread.html
zip_fread · libzip
zip_fread() was added in libzip 0.6. In libzip 0.10 the return type was changed from ssize_t to zip_int64_t.
🌐
Code::Blocks
forums.codeblocks.org › index.php
first use of C::B >> undefined references
February 23, 2006 - As usual while waiting for the next release - don't forget to check the nightly builds in the forum. Home · Help · Search · Login · Register · Code::Blocks Forums » · User forums » · Help » · first use of C::B >> undefined references · « previous next » ·
🌐
Gentoo Forums
forums.gentoo.org › viewtopic-t-751742.html
Gentoo Forums :: View topic - [solved] Error emerging libzip and others
FAQ | Search | Memberlist | Usergroups | Statistics | Profile | Log in to check your private messages | Log in | Register · Links: forums.gentoo.org | www.gentoo.org | bugs.gentoo.org | wiki.gentoo.org | forum-mods@gentoo.org
🌐
PHP
php.net › manual › en › function.zip-open.php
PHP: zip_open - Manual
<?php $za = new ZipArchive(); $za->open('./xc.zip', ZipArchive::CREATE|ZipArchive::OVERWRITE); $file = './notes.txt'; if( true === $za->addFile($file)){ unlink($file); } if(!$za->close()){ echo 'failure.'; } ?> ... For bisqwit at iki dot fi solution of alternative functions there's just one problem when trying to read the file thats because some bug in fread when handling from popen so it just load 8192 bytes here's the function corrected.
🌐
Launchpad
answers.launchpad.net › ubuntu › +source › zlib › +question › 174993
Question #174993 “Undefined reference to zlib in Ubuntu 11.10” : Questions : zlib package : Ubuntu
October 17, 2011 - This built fine in 11.04 but under 11.10 it fails with: undefined reference to symbol 'inflateInit2_' /usr/bin/ld: note: 'inflateInit2_' is defined in DSO /usr/lib/ ... During cmake build step I can see zlib has been found successfully using cmake 2.8.5 -- Found ZLIB: /usr/lib/ ... Removing the -lz from the build line I get a bunch of errors showing that zlib isn't referenced (as I would expect). So what is special about inflateInit2_? ... Zip...
🌐
Stack Overflow
stackoverflow.com › questions › 15023516 › compiler-doesnt-find-reference-to-zip-get-num-entries-on-windows
c++ - Compiler doesn't find reference to zip_get_num_entries on Windows - Stack Overflow
So I searched in their Mercurial ... ... "Undefined reference" means that there is no definition/implementation (as opposed to declaration/prototype) of the function available....
🌐
PHP
bugs.php.net › bug.php
PHP :: Bug #81613 :: impossible to compile php with zip support
November 12, 2021 - go to bug id or search bugs for · Before you report a bug, please make sure you have completed the following steps:
🌐
Stack Overflow
stackoverflow.com › questions › 72836416 › libzip-zip-fread-on-image-stops-at-null-byte-corrupt-images-c
zip - libzip zip_fread on image stops at null byte - corrupt images - c++ - Stack Overflow
July 2, 2022 - When trying to unzip an image file using libzip, I have run across the issue where in the image data, I hit a null byte and libzip zip_fread sees this as EOF and stops reading the file, resulting i...
🌐
Arch Linux Man Pages
man.archlinux.org › man › zip_fread.3.en
zip_fread(3) — Arch manual pages
zip_fread() was added in libzip 0.6. In libzip 0.10 the return type was changed from ssize_t to zip_int64_t.
🌐
Debian Manpages
manpages.debian.org › testing › libzip-dev › zip_fread.3.en.html
zip_fread(3) — libzip-dev — Debian testing — Debian Manpages
March 12, 2024 - zip_fread() was added in libzip 0.6. In libzip 0.10 the return type was changed from ssize_t to zip_int64_t.