undefined reference to `gzopen` error
Asked Answered
G

1

13

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

Glowing answered 4/2, 2012 at 22:29 Comment(6)
Please show your linking command. You might have put -lz in the wrong place.Alkylation
how are you exactly compiling? CFLAGS are used by scripts generated with automake, not gcc directly...Charade
@HubertKario -- CFLAGS is understood (and used) by make; it's fed to the C compiler as appropriate.Tarragon
like this: gcc -Wall -pthread -lm -lz -std=c99 -Wextra src/main.c -o adGlowing
Solved it! I tried all positions of -lz inside my CFLAGS, but I actually had to put it AFTER the source file name.. so the command:"gcc -Wall -pthread -lm -std=c99 -Wextra src/main.c -lz -o ad" worked!Glowing
How about answering the question your self with the comment above? Then mark as accepted.Playgoer
E
13

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

gcc -Wall -pthread  src/main.c -lm -lz -std=c99 -Wextra -o main
Elegancy answered 27/9, 2012 at 19:43 Comment(1)
/usr/bin/c++ libbpf.c:(.text+0x3115): undefined reference to `gzopen'Stowage

© 2022 - 2024 — McMap. All rights reserved.