undefined reference to `gzopen` error

jay1189947 picture jay1189947 · Feb 4, 2012 · Viewed 16.5k times · Source

My C program uses some zlib functions (like gzopen, gzread). I have included the zlib.h header file in my program and added the -lz option when compiling, but I still get an error that the gz functions have undefined references. I'm using kubuntu 11.10 and got the following packages installed: libgh-zlib-dev, zlib1g-dbg, zlib1g and zlib1g-dev.

i have tried changing the position of the linking command, but no luck. Here is the one i have at the moment:

CFLAGS=-Wall -pthread -lm -lz -std=c99 -Wextra

Answer

Giuseppe Scrivano picture Giuseppe Scrivano · Sep 27, 2012

put them as part of LDFLAGS, it should look like:

gcc -Wall -pthread  src/main.c -lm -lz -std=c99 -Wextra -o main