Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to `gzopen` error

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

like image 403
jay1189947 Avatar asked Feb 04 '12 22:02

jay1189947


1 Answers

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

gcc -Wall -pthread  src/main.c -lm -lz -std=c99 -Wextra -o main
like image 171
Giuseppe Scrivano Avatar answered Oct 14 '22 02:10

Giuseppe Scrivano