1

After failing to install a C++ libzip wrapper named libzippp because of a broken Cmake, I decided to compile/link it myself as it's tiny enough.

Problem is that this lib has two dependencies, zlib and libzip. So I Cmaked those two and proceeded into making the .a using MinGW (win32). I then linked my library to my program and then compiled it, no errors.

Code below:

//lib creation command lines  

    g++ -c libzippp.cpp -o libzippp.o -std=c++11 -lzlib -lzip
    ar rcs libzippp.a libzippp.o

//Programm compilation (simplified)

    $(CC) -o $(EXEC) $(OBJ) $(CLFLAG) -lzip -lzlib -lzippp

After that I tried executing basic libzippp methods but here began the errors as the linker calls out for undefined reference.

The undefined reference comes from inside the lib, they're undefined references to the "Libzip" dependency

c:/mingw/bin/../lib/gcc/mingw32/5.3.0/.././..
  /libzippp.a(libzippp.o):libzippp.cpp:(.text+0x236e): 
                                        undefined reference to `_imp__zip_fclose'

But if I simply compile my program using libzippp as a simple compile unit I'm able to use the lib without any linker errors.

Example below :

//Compilation works, lib works

    $(CC) -o $(EXEC) $(OBJ) libzippp.h libzippp.cpp $(CLFLAG) -lzip -lzlib

As a I'm not a very experienced programmer I've assumed that I just failed the creation of the lib. It's the first time I've make a lib that needs other libs to work and I believe my error come from here.

A. Delran
  • 517
  • 2
  • 9
  • `CLFLAG` is a very non-standard name for compilation flags. Better use separate `CFLAGS` and `LDFLAGS`. Also you do not need to specify libs when compiling `libzippp.o`. – yugr Apr 24 '17 at 12:28
  • I just didn't wrote my LDFLAGS var as it only contained the tree libs and I wanted it as lisible as possible, and I just forgot the S at the end of CLFLAG. – A. Delran Apr 24 '17 at 15:00

1 Answers1

0

You need to move -lzippp before -lzip, otherwise linker will not link files from libzip:

$(CC) -o $(EXEC) $(OBJ) $(CLFLAG) -lzippp -lzip -lzlib

That's how static libs work.

yugr
  • 19,769
  • 3
  • 51
  • 96