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 OverflowCompilation issue concerning zip
c++ - Odd undefined reference errors - Stack Overflow
QuaZip - Undefined Reference
c++ - Error with zip_open from libzip - Stack Overflow
I had a very similar problem with unzGoToFirstFile. If you download the ZLib sources and do a simple "grep -irl unzGoToFirstFile" you'll find that these functions are not part of ZLib at all. They are however part of a contributed library called minizip found within the ZLib sources.
Add this to the ZLib CMakeLists.txt somwhere near the bottom and it will create a library called "libunzip.a" with the required unzGoToFirstFile etc functions you require. Just link your program towards that and you should be golden.
set(UNZIP_SOURCES "contrib/minizip/unzip.c"
"contrib/minizip/zip.c"
"contrib/minizip/ioapi.c")
set(UNZIP_HEADERS "contrib/minizip/unzip.h"
"contrib/minizip/zip.h"
"contrib/minizip/ioapi.h")
add_library(unzip STATIC
"${UNZIP_SOURCES}"
"${UNZIP_HEADERS}")
target_link_libraries(unzip zlibstatic)
install(TARGETS unzip
RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" )
install(FILES ${UNZIP_HEADERS} DESTINATION "${CMAKE_INSTALL_PREFIX}/include")
I think, you forgot to add the zlib to the library list.
If you're using MSVC, go to your project settings, open the Linker settings and add zlib.lib (I believe this is the filename of libz for win32) to the additional dependencies.
If you're using gcc, add -lzlib (or was it -lz ?) to your commandline.
It looks like you haven't linked to libzip. Make sure you are infact linking to it, and that the path to the lib is in your link path.
Judging by the discussion on this thread from the libzip-discuss list it looks like you are trying to link against a static version of libzip but with the preprocessor symbol ZLIB_DLL defined. You should only have ZLIB_DLL defined if linking against the dll version.