I am learning Nim and love it so far, but I have a problem that I can't figure out. Is there anyone that could provide some advice?
I was trying to write some code to process Excel files. I installed the XLSX library using Nimble, but when I try to compile the code, the linker generates an error
...
Hint: [Link]
c:/nim/nim-2.0.0/dist/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lz
collect2.exe: error: ld returned 1 exit status
...
I found some previous posts on the forum that suggest modify the nim.cfg file, but the -lz option does not appear. What really baffles me is that I tried the XL library (https://github.com/khchen/xl) and this works correctly. I looked at both of the libraries .nimble files and the requirements are very similar. They both require "zippy".
I tried this on two different Windows 10 servers and got the same issue. My Nim version is Nim Compiler Version 2.0.0 [Windows: amd64]
When Nim compile your code, Nim generates C files and call the backend C compiler. In your case, the backend C compiler is GCC. GCC compiles the generated C file and generates a object file. Generated object files and libraries are linked by ld.exe and it generates an executable file. -lz option adds a library to the linker. https://sourceware.org/binutils/docs-2.41/ld/Options.html https://sourceware.org/binutils/docs-2.41/ld/WIN32.html
It seems one of imported libraries in your project try to link libz but you don't have that library.
xlsx shouldn't require external libz dependency since v0.4.7.
Maybe you have outdated version installed? You can check all installed package versions with nimble list -i.
You can also put this in your project's .nimble file:
requires "xlsx >= 0.4.8"
Then build the project with nimble build, and nimble should install the right version for you.