How to import zip package (NOT)
Running on Ubuntu 14.04.3 LTS
I have used nimble to install the zip package and this seems to work.
I place
import zip
in an otherwise compiling xxx.nim file.
It produces a "cannot open 'zip'" error message when recompiled.
Running nimble list -i provides:
nimble [0.6.2]
gtk2 [1.0]
aporia [0.2.0]
zip [0.1.0]
dialogs [1.0]
cairo [1.0]
and replacing the "import zip" by a "import cairo" or "import gtk2" statement compiles just fine - implying that nim CAN find the nimbleDir (which is ~/.nimble)
I have googled and "nim forum"-ed the issue as "import zip" and cannot seem to find an answer.
What is being done wrong?
You may see
https://github.com/nim-lang/zip/blob/master/zip/zipfiles.nim
So my guess is, that zip is the nimble package name, but for import you should use libzip?
Good thought, so I tried "import libzip", but it said "cannot open 'libzip'"
I double checked that "import cairo" works and it does.
Nor would nimble install a "libzip".
But thanks.
You should be able to import like so:
import zip/zipfiles
apologies for resurrecting a zombie thread, but when I try and gcc it, it errors with:
zip_zipfiles.o:zip_zipfiles.c:(.text+0xab): undefined reference to `zip_open'
zip_zipfiles.o:zip_zipfiles.c:(.text+0x408): undefined reference to `zip_strerror'
zip_zipfiles.o:zip_zipfiles.c:(.text+0x575): undefined reference to `zip_source_file'
zip_zipfiles.o:zip_zipfiles.c:(.text+0x5b2): undefined reference to `zip_add'
zip_zipfiles.o:zip_zipfiles.c:(.text+0x5c7): undefined reference to `zip_source_free'
zip_zipfiles.o:zip_zipfiles.c:(.text+0x5f6): undefined reference to `zip_close'
collect2: error: ld returned 1 exit status
The zip package also does not work on windows. Are you on windows?
I wish zip and gzip was part of standard library...
I'm not. More details here:https://forum.nim-lang.org/t/4108
tldr; reproducible Dockerfile at https://github.com/yatesco/docker-nim-dev-example
@yatesco, did you install libzip? In your docker file, it doesn't seem to be installed. I had to do
sudo apt-get install libzip-dev
in order to get the code to work.
Thanks @jyapayne, I had tried that before, but it didn't make any difference, it still reports:
zip_zipfiles.o:zip_zipfiles.c:(.text+0xab): undefined reference to `zip_open'
zip_zipfiles.o:zip_zipfiles.c:(.text+0x408): undefined reference to `zip_strerror'
zip_zipfiles.o:zip_zipfiles.c:(.text+0x575): undefined reference to `zip_source_file'
zip_zipfiles.o:zip_zipfiles.c:(.text+0x5b2): undefined reference to `zip_add'
zip_zipfiles.o:zip_zipfiles.c:(.text+0x5c7): undefined reference to `zip_source_free'
zip_zipfiles.o:zip_zipfiles.c:(.text+0x5f6): undefined reference to `zip_close'
collect2: error: ld returned 1 exit status
When it finishes correctly it produces a linux.exe and windows.exe - are you saying you managed to get that to work?
Right, but that error you posted is for the Windows build. The linux build should work after the libzip addition if you put -ldl like so:
gcc -o linux.exe nimcache/*.c -ldl
The windows build is a bit more tricky. You'll have to cross compile zlib for windows as well and then link to it in the gcc step. That will provide the zip_open, etc functions.
Ah OK. I did put a great big "NEWBIE" warning ;-). Unfortunately though, the linux build still doesn't work as it errors out with:
/tmp/ccb40CFm.o: In function `nimLoadLibrary':
stdlib_system.c:(.text+0x6b6c): undefined reference to `dlopen'
/tmp/ccb40CFm.o: In function `nimGetProcAddr':
stdlib_system.c:(.text+0x6cb5): undefined reference to `dlsym'
collect2: error: ld returned 1 exit status
cp: cannot stat 'linux.exe': No such file or directory
I fully expect that is a missing dependency too, but apt install libltdl-dev (which came up in apt search dlopen) didn't fix it either.
You should be able to replace your call for the linux build with:
nim c --cpu:amd64 --os:linux --opt:speed --embedsrc --threads:on --checks:on -d:release src/*.nim
cp src/docker_nim_dev_example $my_pwd/dist/linux.exe
(notice the -c removal)
Similarly, you can do the same for the windows build but also add in the gcc linker/compiler:
nim c --cpu:amd64 --os:windows --opt:speed --embedsrc --threads:on --checks:on --gcc.exe:x86_64-w64-mingw32-gcc --gcc.linkerexe:x86_64-w64-mingw32-gcc -d:release src/*.nim
cp src/docker_nim_dev_example.exe $my_pwd/dist/windows.exe
However, like I mentioned above, since the Windows build will compile libzip from a C file in the nim-lang/zip repo (here), you need to compile and link zlib using x86_64-w64-mingw32-gcc from here.
After you compile it using:
PREFIXDIR=/usr/x86_64-w64-mingw32 BINARY_PATH=$PREFIXDIR/bin INCLUDE_PATH=$PREFIXDIR/include LIBRARY_PATH=$PREFIXDIR/lib SHARED_MODE=1 PREFIX=x86_64-w64-mingw32- make -f win32/Makefile.gcc
(The above basically tells the Makefile to use everything from the cross compiler directory.)
You can then do this:
nim c --cpu:amd64 --os:windows --opt:speed --embedsrc --threads:on --checks:on --gcc.exe:x86_64-w64-mingw32-gcc --gcc.linkerexe:x86_64-w64-mingw32-gcc -d:release --passL:"-L/home/joey/Downloads/zlib1211/zlib-1.2.11/ -lzlib1" --passC:"-I/home/joey/Downloads/zlib1211/zlib-1.2.11/" src/*.nim
cp src/docker_nim_dev_example.exe $my_pwd/dist/windows.exe
@yatesco I've made a PR to your repo with the fixes!