collect2.exe: error: ld returned 1 exit status

user3695946 picture user3695946 · Jul 14, 2014 · Viewed 29.5k times · Source

Please I need help when I try to compile my .C to png

gcc --std=c99 -Wall -lz a.c -o a.png
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lz
collect2.exe: error: ld returned 1 exit status

What does this mean?

Answer

Ananya picture Ananya · Jun 26, 2017

From the error message, the linker says that it can not find libz.so or libz.a. If you are providing that lib from your own path, tell the linker that it has to search in your path, by

gcc --std=c99 -Wall -Ldir -lz a.c -o a.png

use

ld -lz --verbose 

to see where linker has searched for libz.