Linux Makefile: undefined reference to 'gzbuffer' (where LIB = -lz)

5.4k Views Asked by At

I'm trying to install a program (vcftools), for which the Makefile reads as follows:

# Make file for vcftools
# Author: Adam Auton
# ($Revision: 230 $)

# Compiler
CPP = g++
# Output executable
EXECUTABLE = vcftools
# Flag used to turn on compilation of PCA routines
ifndef VCFTOOLS_PCA
        VCFTOOLS_PCA = 0
endif
# Compiler flags
CPPFLAGS = -O2 -Wall -Wextra -D_FILE_OFFSET_BITS=64
#CPPFLAGS = -g 
# Included libraries (zlib)
#LIB = -lz 
LIB = -lz -I/usr/local/include/ -L/usr/local/lib/


OBJS = vcftools.o vcf_file.o vcf_entry.o \
                vcf_entry_getters.o vcf_entry_setters.o \
                vcf_file_filters.o vcf_file_output.o \
                vcf_file_format_convert.o \
                vcf_file_diff.o parameters.o \
                vcf_file_index.o \
                output_log.o

I have not been able to get this Makefile to run correctly, but instead get an error that reads:

vcf_file.cpp:(.text+0xe72): undefined reference to `gzbuffer'
collect2: ld returned 1 exit status
make[1]: *** [vcftools] Error 1
make[1]: Leaving directory `/home/Public/Packages/vcftools_0.1.10/cpp'
/bin/sh: 2: cd: can't cd to perl
make: *** [install] Error 2

I think part of the problem is that there is an error related to my zlib installation path. I've tried to change the -I and -L paths to match my zlib installation, but haven't had any luck (there are a lot of folders that seem to contain zlib files).

Further, by searching through other forums related to this program (here), it seems that I may need zlib1g-dev. zlib1g-dev is on my computer (it shows up in my ubuntu software center), but doesn't show up when I enter:

root@root:/home/Public/Packages/vcftools_0.1.10/cpp# whereis zlib1g-dev
zlib1g-dev:
root@root:/home/Public/Packages/vcftools_0.1.10/cpp# which zlib1g-dev

I've considered removing and re-installing zlib, but it looks like several programs are dependent on it. When trying to run an install or remove, I get the following message:

sudo apt-get install zlib-devel

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package zlib-devel

I'm not sure if the problem lies in where zlib is installed on my computer, an error in the installation, or something else entirely over my head. Any suggestions would be greatly appreciated. Thank you.

6

There are 6 best solutions below

0
On

On my system (Ubuntu 12.04.3 LTS), it was a lib location issue.
Make sure the zlib1g-dev is installed.
In the vcftools_whatever/cpp/Makefile, change

LIB = -lz

to

LIB = -L/usr/local/lib/ -lz
0
On

I found this by searching on undefined reference to gzbuffer var. The error came up compiling ImageMagick from source on a CentOS-6.6 Linux box. I had to do two things: 1) As per suggestion re. Ubuntu, by travc, You edit the Makefile, look for "LIBS = " (which was blank in my case), and change it to "LIBS = -L/usr/local/lib -lz". That got me a clean compile. Ran "make install" to install the thing, and it failed at runtime. 2) The fix was to cd to /usr/local/lib and just run "ldconfig" from command line. "ldconfig" updates dynamic linker runtime bindings (read the "man" page for details.) You confirm ImageMagick installed ok by running "display" at command line, in X-windows. (If you have ImageMagick installed so that "display" prgm works, Python and its various graphics/image generating tools will use it automatically, allowing one to render and inspect complex images which exceed screen size).

0
On

For vcftools had to modify, after the configure:

  1. Makefile

  2. src/Makefile

  3. src/cpp/Makefile

And in each, go to LIBS and put:

LIBS = -L/tools/hpclib/zlib-1.2.8/lib -lz -lgomp

This is on centos with zlib compiled in the specific location above.

0
On

I think you miss the devel package. It is not called zlib-devel as you tried,

sudo apt-get install zlib-devel

but zlib1g-dev. So the command for you to run is:

sudo apt-get install zlib1g-dev

0
On

This worked for me, putting this in my Makefile:

By the way, I spent 10 minutes with it not working because I had left off lib at the end of this line and just had the root path.

LIBS = -L/tools/hpclib/zlib-1.2.8/lib -lz -lgomp (worked)

LIBS = -L/tools/hpclib/zlib-1.2.8 -lz -lgomp (didn't work)

Hope that helps someone. It was for compiling a program called stacks 2.41

0
On

There is a bug in obuntu in that area, where the declaration of a particular library must appear after the declaration of the library path.

In your makefile the -lz can only be placed after -L/usr/local/lib/

I would suggest to change the LIB declaration to the one below - that should fix the problem

LIB = -I/usr/local/include/ -L/usr/local/lib/ -lz