1

I recently compiled libzip (and zlib) statically on windows 10 and i'm playing with it on visual Studio 2017.I followed instructions on this thread,adapted it a bit to build with VS2017,and modified CMakelists.txt to build the library statically:

I added this to the end of the file :

ADD_LIBRARY(zipstatic STATIC ${LIBZIP_SOURCES} ${LIBZIP_EXTRA_FILES} ${LIBZIP_OPSYS_FILES})
SET_TARGET_PROPERTIES(zipstatic PROPERTIES VERSION 3.0 SOVERSION 3 )
TARGET_LINK_LIBRARIES(zipstatic ${ZLIB_LIBRARY} ${OPTIONAL_LIBRARY})
INSTALL(TARGETS zipstatic
  RUNTIME DESTINATION bin
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib)

I also used patch from here to get rid of STDIN_FILENO error when compiling libzip.

Build processes went fine,i added zlibstatic.lib and libzipstatic.lib to my linker options,and set up Runtime Library to /MT

I wrote this tiny code to see if everything's working:

#include "stdafx.h"
#include <zip.h>
#include <zlib.h>




int main()
{
    zip *archive = zip_open("C:\\test.zip", ZIP_CREATE, 0);

    return 0;
}

This kind of error often appears when linking against static lib instead of DLL's,but i compiled libzip statically (and i need to use static linking),so what do I have to do ?

EDIT : zipstatic.lib summary:

      C8 .data
      60 .debug$F
    45C4 .debug$S
    21BD .drectve
    2690 .rdata
   113C1 .text$mn

and zlibstatic.lib's summary :

    50 .debug$F
    860 .debug$S
    2C1 .drectve
    4317 .rdata
    ADB6 .text$mn
EinderJam
  • 417
  • 1
  • 6
  • 20
  • Did you add path where linker need to look for `zlibstatic.lib` and `libzipstatic.lib`? – user7860670 Nov 04 '17 at 10:15
  • @VTT Missing the path doesn't result in a _undefined reference_ error. – user0042 Nov 04 '17 at 10:16
  • 1
    @user0042 It may actually if incorrect library version is found. – user7860670 Nov 04 '17 at 10:17
  • @VTT Good point, yes. – user0042 Nov 04 '17 at 10:17
  • @VTT yes : http://image.noelshack.com/fichiers/2017/44/6/1509791422-capture-d-ecran-58.png – EinderJam Nov 04 '17 at 10:31
  • You should check what actually is contained in those static libraries using dumpbin tool. Maybe it wasn't built correctly. – user7860670 Nov 04 '17 at 10:56
  • You should make sure your project does not define `ZLIB_DLL`. – Michaël Roy Nov 04 '17 at 11:55
  • @Michaël Roy : The only place I see `ZLIB_DLL` is in `zipconf.h`,with a `ifdef ZLIB_DLL.....`,but I didn't see any `define ZLIB_DLL` anywhere. – EinderJam Nov 04 '17 at 12:36
  • 2
    Maybe in the project configuration? That macro is the only thing that could make your app expect the library coming from a dll. The __imp_ prefix is a dead giveaway (that's linked to a __cdecl(dllimport) declaration). Look in both your VS project and in the cmake project for the library. You can also try adding `#undef ZLIB_DLL` in your stdafx.h – Michaël Roy Nov 04 '17 at 21:38
  • @MichaëlRoy Thanks for the hint with the dllimport. It pointed me to the solution on my side: As I want to use static libs of libzip I need to define `ZIP_STATIC` in my project preprocessor settings. The header expects this define when using static libs, otherwise it adds the dllimport via the ZIP_EXTERN define. – Danielku15 Feb 16 '18 at 20:22
  • Glad to hear you could move forward on your project. – Michaël Roy Feb 16 '18 at 22:30

0 Answers0