Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zipfiles does not work on windows machine. #33

Closed
puruneko opened this issue Dec 3, 2018 · 3 comments
Closed

zipfiles does not work on windows machine. #33

puruneko opened this issue Dec 3, 2018 · 3 comments

Comments

@puruneko
Copy link

puruneko commented Dec 3, 2018

Problem

On my Windows environment, zipfiles.nim does not work at all.

Situation

When execute nim compiling, compiler shows messages that compiling libzip_all.c is failed.
It seems that zlib.h is not linked.
Sample source code is following as:

import zip/zipfiles
proc main() =
  var fpZip: ZipArchive
  defer: fpZip.close()
  discard fpZip.open(r"C:\Users\puruneko\archive.zip")
  for path in fpZip.walkFiles:
    echo path
when isMainModule:
  main()

Example message of compiling is folloing as:

C:\Users\puruneko\nimcache\sample_d\libzip_all.c.o:libzip_all.c:(.text+0x112): undefined reference to `zError'
C:\Users\puruneko\nimcache\sample_d\libzip_all.c.o:libzip_all.c:(.text+0x2be0): undefined reference to `crc32'
C:\Users\puruneko\nimcache\sample_d\libzip_all.c.o:libzip_all.c:(.text+0x2c86): undefined reference to `deflateInit2_'
C:\Users\puruneko\nimcache\sample_d\libzip_all.c.o:libzip_all.c:(.text+0x2d35): undefined reference to `deflateEnd'
C:\Users\puruneko\nimcache\sample_d\libzip_all.c.o:libzip_all.c:(.text+0x2da4): undefined reference to `crc32'
C:\Users\puruneko\nimcache\sample_d\libzip_all.c.o:libzip_all.c:(.text+0x2dce): undefined reference to `deflate'
C:\Users\puruneko\nimcache\sample_d\libzip_all.c.o:libzip_all.c:(.text+0x2ed6): undefined reference to `deflateEnd'
C:\Users\puruneko\nimcache\sample_d\libzip_all.c.o:libzip_all.c:(.text+0x37ad): undefined reference to `zError'
C:\Users\puruneko\nimcache\sample_d\libzip_all.c.o:libzip_all.c:(.text+0x3860): undefined reference to `inflateEnd'
C:\Users\puruneko\nimcache\sample_d\libzip_all.c.o:libzip_all.c:(.text+0x39bc): undefined reference to `crc32'
C:\Users\puruneko\nimcache\sample_d\libzip_all.c.o:libzip_all.c:(.text+0x3ab1): undefined reference to `crc32'
C:\Users\puruneko\nimcache\sample_d\libzip_all.c.o:libzip_all.c:(.text+0x3fff): undefined reference to `inflateInit2_'
C:\Users\puruneko\nimcache\sample_d\libzip_all.c.o:libzip_all.c:(.text+0x42ec): undefined reference to `crc32'
C:\Users\puruneko\nimcache\sample_d\libzip_all.c.o:libzip_all.c:(.text+0x69c7): undefined reference to `crc32'
C:\Users\puruneko\nimcache\sample_d\libzip_all.c.o:libzip_all.c:(.text+0x6a32): undefined reference to `inflate'
C:\Users\puruneko\nimcache\sample_d\libzip_all.c.o:libzip_all.c:(.text+0x6abd): undefined reference to `crc32'

Temporary solution

Compiling only libzip_all.c can succeed. (gcc -shared libzip_all.c -o libzip_all.dll -lz)
It seems that libzip_all.c is correct because of the above, so I checked libzip.nim.
Then, places that seems suspicious were found in the upper when blocks:

when defined(unix) and not defined(useLibzipSrc):
  when defined(macosx):
    {.pragma: mydll, dynlib: "libzip(|2|4).dylib".}
  else:
    {.pragma: mydll, dynlib: "libzip(|2).so(|.4|.2|.1|.0)".}
else:
  when defined(unix):
    {.passl: "-lz".}
  {.compile: "zip/private/libzip_all.c".}
  {.pragma: mydll.}

In the above code, when the case of windows machine, it seems that libzip_all.c is compiled without -lz option.
So, I changed codes following as:

else:
  {.passl: "-lz".}
  {.compile: "zip/private/libzip_all.c".}
  {.pragma: mydll.}

It startrd to move for now...
But, is this a correct solution?

Postscripts

Please pardon my poor English.

@Araq
Copy link
Member

Araq commented Dec 4, 2018

I don't know but if it works for you, please create a PR.

@puruneko
Copy link
Author

Thanks for your advice.
I found similar PR, so closing this issue.

@FabienPoirierPrincipia
Copy link

I am using nim 1.0.4 and I just falled in this issue, but the trick given above is working fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants