1

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 
James Black
  • 102
  • 1
  • 7
  • [This will proabably help you.](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) Other than that, are you sure the library is included in where it's searching for them? – chris Sep 29 '12 at 04:35
  • 1
    Do you have `#include ` in your `svr_tick.c` file, and `-I/usr/local/zlib/include` in your compile command line? (The linker is irrelevant, because you haven't even gotten past the compilation.) – abarnert Sep 29 '12 at 05:15
  • 1
    One more thing: I'm not on Ubuntu, but it seems very suspicious that zlib.h is in `/usr/local/zlib/include` rather than `/usr/include`. Do you have multiple versions of zlib-dev (or zlib1g-dev) installed, or have you done something odd with your apt configuration, or has Ubuntu drastically reorganized things since the last time I had a deb-based system? – abarnert Sep 29 '12 at 05:28
  • Following up: http://packages.ubuntu.com/oneiric/amd64/zlib1g-dev/filelist shows that you should indeed have `/usr/include/zlib.h`. So, where did that `/usr/local/zlib` come from? – abarnert Sep 29 '12 at 05:30
  • I can confirm /usr/include contains a zlib.h but that zlib.h doesn't have deflate End. I have included the one that does in its place, no change. – James Black Sep 29 '12 at 05:38
  • I didn't check /usr/include before because I haven't ever used this system before. Also I can confirm #include and "zlib.h" do not change anything. I will now check to see if im including your -I/usr/local/zlib/include in the right spot. – James Black Sep 29 '12 at 05:40
  • I attempted to add -I. check the edit above for exact command, no change. – James Black Sep 29 '12 at 05:41

1 Answers1

5

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

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • This fixed that error, but now im getting... cgilib/cgi-lib.a(cgi-lib.o)' is incompatible with i386:x86-64 output – James Black Sep 29 '12 at 06:19
  • That must be from building a different executable since the commands above don't mention `cgilib/cgi-lib.a`. It appears that the library is built incorrectly. You will need to review how it was built, or simply remove it and the object files it was built from and build again. If the problem reoccurs, then you have to do some more detailed analysis. Look at the output of `file *.o` on the object files you're linking. Then look at the object files for the `cgilib/cgi-lib.a` file (extract them from the archive into a sub-directory to look at them). See what's different and work out what went bad. – Jonathan Leffler Sep 29 '12 at 06:29