简体   繁体   中英

Cannot Build C Application with GCC because of undefined reference to 'deflateEnd'

Here is the error snippet

/home/jamesblack/Development/v2server/svr_tick.c:1309: undefined reference to `deflateEnd'

This happens when I run my makefile, it looks like it runs this command.

gcc -O -g -lm -lz -lcrypt -o server .obj/server.o .obj/svr_disk.o .obj/svr_tick.o .obj/svr_act.o .obj/driver.o .obj/svr_god.o .obj/svr_do.o .obj/svr_glob.o .obj/build.o .obj/use_driver.o .obj/look_driver.o .obj/svr_effect.o .obj/driver_etc.o .obj/driver_generic.o .obj/populate.o .obj/helper.o .obj/skill.o .obj/skill_driver.o .obj/talk.o .obj/area.o .obj/path.o .obj/stunrun.o .obj/cityattack.o .obj/npc_malte.o .obj/lab9.o .obj/rdtsc.o .obj/ccp_driver.o  

And then it spouts of alot of errors similar to that, everything i've googled mentions installing zlib and linking it with -lz, which is clearly in the make command, also im pretty sure i installed it right. apt-get install zlib1g-dev in ubuntu 11 64bit

Any thoughts

EDIT:

My zlib.h located at /usr/local/zlib/include/zlib.h includes this

ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
/*
 All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any pending
output.

 deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
stream state was inconsistent, Z_DATA_ERROR if the stream was freed
prematurely (some input or output was discarded).  In the error case, msg
may be set but then points to a static string (which must not be
deallocated).
*/

Is this what I need it to have? Also echo $LD_LIBRARY_PATH doens't return anything. Do I truly have Zlib configure properly?

EDIT 2:

gcc -I/usr/local/zlib/include -O -g -lm -lz -lcrypt -o server .obj/server.o .obj/svr_disk.o .obj/svr_tick.o .obj/svr_act.o .obj/driver.o .obj/svr_god.o .obj/svr_do.o .obj/svr_glob.o .obj/build.o .obj/use_driver.o .obj/look_driver.o .obj/svr_effect.o .obj/driver_etc.o .obj/driver_generic.o .obj/populate.o .obj/helper.o .obj/skill.o .obj/skill_driver.o .obj/talk.o .obj/area.o .obj/path.o .obj/stunrun.o .obj/cityattack.o .obj/npc_malte.o .obj/lab9.o .obj/rdtsc.o .obj/ccp_driver.o 

Put the libraries after the object files, so modify the makefile or rewrite the link command so that instead of being like this (as in the question):

gcc -O -g -lm -lz -lcrypt -o server .obj/server.o .obj/svr_disk.o .obj/svr_tick.o \
    .obj/svr_act.o .obj/driver.o .obj/svr_god.o .obj/svr_do.o .obj/svr_glob.o \
    .obj/build.o .obj/use_driver.o .obj/look_driver.o .obj/svr_effect.o \
    .obj/driver_etc.o .obj/driver_generic.o .obj/populate.o .obj/helper.o \
    .obj/skill.o .obj/skill_driver.o .obj/talk.o .obj/area.o .obj/path.o \
    .obj/stunrun.o .obj/cityattack.o .obj/npc_malte.o .obj/lab9.o \
    .obj/rdtsc.o .obj/ccp_driver.o  

It should be like this:

gcc -O -g -o server .obj/server.o .obj/svr_disk.o .obj/svr_tick.o .obj/svr_act.o \
    .obj/driver.o .obj/svr_god.o .obj/svr_do.o .obj/svr_glob.o .obj/build.o \
    .obj/use_driver.o .obj/look_driver.o .obj/svr_effect.o .obj/driver_etc.o \
    .obj/driver_generic.o .obj/populate.o .obj/helper.o .obj/skill.o \
    .obj/skill_driver.o .obj/talk.o .obj/area.o .obj/path.o .obj/stunrun.o \
    .obj/cityattack.o .obj/npc_malte.o .obj/lab9.o .obj/rdtsc.o .obj/ccp_driver.o \
    -lm -lz -lcrypt

The linker only pulls in symbols from shared libraries if at least one of the symbols satisfies an outstanding undefined reference; when the libraries come first, they don't usually have a main() and that's what the linker is looking for to start with. (This is a change of behaviour; a few years ago, the linker tended to pull in every shared library, regardless of whether it satisfied any undefined symbols.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM