1

这是错误片段

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

当我运行我的 makefile 时会发生这种情况,看起来它运行了这个命令。

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  

然后它喷出很多类似的错误,我用谷歌搜索的所有内容都提到安装zlib并将其与-lz链接,这显然在make命令中,我也很确定我安装正确。apt-get 在 ubuntu 11 64bit 中安装 zlib1g-dev

有什么想法吗

编辑:

我的 zlib.h 位于 /usr/local/zlib/include/zlib.h 包括这个

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).
*/

这是我需要的吗?也 echo $LD_LIBRARY_PATH 不返回任何内容。我真的正确配置了 Zlib 吗?

编辑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 
4

1 回答 1

5

将库放在目标文件之后,因此修改makefile或重写链接命令,而不是像这样(如问题所示):

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  

它应该是这样的:

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.)

于 2012-09-29T05:48:58.487 回答