nim-lang/zip

[mac os x]: could not import: gzopen

deem0n opened this issue · 2 comments

Actually, I have problems to run example from Arraymancer, which uses zip module to read files

So I isolated the problem into simple gz.nim file:

import zip/gzipfiles

let stream = newGzFileStream("./build/mnist.zip", mode = fmRead)
nim c gz.nim
Hint: used config file '/usr/local/Cellar/nim/0.20.0_1/nim/config/nim.cfg' [Conf]
Hint: used config file '/Users/deem0n/Documents/Projects/Arraymancer/nim.cfg' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: gz [Processing]
Hint: gzipfiles [Processing]
Hint: os [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: math [Processing]
Hint: bitops [Processing]
Hint: macros [Processing]
Hint: algorithm [Processing]
Hint: unicode [Processing]
Hint: pathnorm [Processing]
Hint: osseps [Processing]
Hint: posix [Processing]
Hint: times [Processing]
Hint: options [Processing]
Hint: typetraits [Processing]
Hint: zlib [Processing]
Hint: streams [Processing]
/Users/deem0n/Documents/Projects/Arraymancer/examples/gz.nim(3, 5) Hint: 'stream' is declared but not used [XDeclaredButNotUsed]
CC: stdlib_assertions.nim
CC: stdlib_io.nim
CC: stdlib_system.nim
CC: stdlib_posix.nim
CC: stdlib_times.nim
CC: stdlib_os.nim
CC: ../../../../.nimble/pkgs/zip-0.2.1/zip/zlib.nim
CC: stdlib_streams.nim
CC: ../../../../.nimble/pkgs/zip-0.2.1/zip/gzipfiles.nim
CC: gz.nim
Hint:  [Link]
Hint: operation successful (37824 lines compiled; 0.896 sec total; 46.707MiB peakmem; Debug Build) [SuccessX]

When I run compiled executable, I got:

./gz
could not import: gzopen

It is mac os x 10.14.4 (Mojave)

 nimble list -i
arraymancer  [0.5.0]
c2nim  [0.9.14]
clblast  [0.0.1]
cligen  [0.9.17]
commandeer  [0.12.3]
compiler  [0.19.0]
docopt  [0.6.5]
nats  [1.0.0]
nimblas  [0.2.2]
nimcl  [0.1.3]
nimcuda  [0.1.5]
nimgen  [0.4.0]
nimlapack  [0.1.1]
nimssh2  [0.1.2]
nimssl  [0.1.2]
opencl  [1.0]
regex  [0.8.1]
rosencrantz  [0.3.3]
stb_image  [2.3]
unicodedb  [0.6.0]
unicodeplus  [0.4.0]
untar  [0.1.0]
zip  [0.2.1]
ls -l /usr/lib/libz.*
lrwxr-xr-x  1 root  wheel      12 27 апр 20:34 /usr/lib/libz.1.1.3.dylib -> libz.1.dylib
lrwxr-xr-x  1 root  wheel      12 27 апр 20:34 /usr/lib/libz.1.2.11.dylib -> libz.1.dylib
lrwxr-xr-x  1 root  wheel      12 27 апр 20:34 /usr/lib/libz.1.2.5.dylib -> libz.1.dylib
lrwxr-xr-x  1 root  wheel      12 27 апр 20:34 /usr/lib/libz.1.2.8.dylib -> libz.1.dylib
-rwxr-xr-x  1 root  wheel  186480 16 апр 07:22 /usr/lib/libz.1.dylib
lrwxr-xr-x  1 root  wheel      12 27 апр 20:34 /usr/lib/libz.dylib -> libz.1.dylib

I checked on nimlang/nim:0.20.0-alpine-regular Docker image and it worked fine. So it is Mac OS X problem.

I found how to trace the process: sudo -E dtruss -t open ./gz

SYSCALL(args) 		 = return
could not import: gzopen
open("/dev/dtracehelper\0", 0x2, 0xFFFFFFFFEE013DB0)		 = 3 0
open("/usr/local/lib/libz.dylib\0", 0x0, 0x0)		 = 3 0
open("/usr/local/lib/gcc/6/libgcc_s.1.dylib\0", 0x0, 0x0)		 = 3 0

So nim is looking in /usr/local/lib and I have broken soft link there for the libz.dylib. I installed with homebrew: brew install zlib and linked to installed version

ln -s /usr/local/opt/zlib/lib/libz.dylib /usr/local/lib/libz.dylib

Now it works !