6

I would like to compile some third-party software but I encounter a problem with ZLIB apparently.

See below:

 $sudo make
    gcc -Wall -pedantic -DVERSION=1.2 -lz -O3 sliding.o trim_single.o trim_paired.o sickle.o -o sickle
    trim_paired.o: In function `ks_getuntil':
    trim_paired.c:(.text+0x78): undefined reference to `gzread'
    trim_paired.o: In function `kseq_read':
    trim_paired.c:(.text+0x48d): undefined reference to `gzread'
    trim_paired.c:(.text+0x4dc): undefined reference to `gzread'
    trim_paired.c:(.text+0x60a): undefined reference to `gzread'
    trim_paired.c:(.text+0x687): undefined reference to `gzread'
    trim_paired.o: In function `paired_main':
    trim_paired.c:(.text+0xc62): undefined reference to `gzopen'
    trim_paired.c:(.text+0xc83): undefined reference to `gzopen'
    trim_paired.c:(.text+0x1142): undefined reference to `gzclose'
    trim_paired.c:(.text+0x114f): undefined reference to `gzclose'
    trim_single.o: In function `ks_getuntil':
    trim_single.c:(.text+0x78): undefined reference to `gzread'
    trim_single.o: In function `single_main':
    trim_single.c:(.text+0x688): undefined reference to `gzopen'
    trim_single.c:(.text+0x8ad): undefined reference to `gzread'
    trim_single.c:(.text+0x8f5): undefined reference to `gzread'
    trim_single.c:(.text+0xb11): undefined reference to `gzread'
    trim_single.c:(.text+0xb96): undefined reference to `gzread'
    trim_single.c:(.text+0xc58): undefined reference to `gzclose'
    collect2: ld returned 1 exit status
    make: *** [build] Error 1

I am using Ubuntu and I did install ZLIB 1.2.6 in /usr/local/lib

Here is the Makefile:

PROGRAM_NAME = sickle
VERSION = 1.2
CC = gcc
CFLAGS = -Wall -pedantic -DVERSION=$(VERSION)
DEBUG = -g
OPT = -O3
ARCHIVE = $(PROGRAM_NAME)_$(VERSION)
LDFLAGS = -lz
SDIR = src

.PHONY: clean default build distclean dist debug

default: build

sliding.o: $(SDIR)/sliding.c $(SDIR)/kseq.h $(SDIR)/sickle.h
    $(CC) $(CFLAGS) $(OPT) -c $(SDIR)/$*.c

trim_single.o: $(SDIR)/trim_single.c $(SDIR)/sickle.h $(SDIR)/kseq.h
    $(CC) $(CFLAGS) $(OPT) -c $(SDIR)/$*.c

trim_paired.o: $(SDIR)/trim_paired.c $(SDIR)/sickle.h $(SDIR)/kseq.h
    $(CC) $(CFLAGS) $(OPT) -c $(SDIR)/$*.c

sickle.o: $(SDIR)/sickle.c $(SDIR)/sickle.h
    $(CC) $(CFLAGS) $(OPT) -c $(SDIR)/$*.c

clean:
    rm -rf *.o $(SDIR)/*.gch ./sickle

distclean: clean
    rm -rf *.tar.gz

dist:
    tar -zcf $(ARCHIVE).tar.gz src Makefile

build: sliding.o trim_single.o trim_paired.o sickle.o
    $(CC) $(CFLAGS) $(LDFLAGS) $(OPT) $? -o sickle

debug:
    $(MAKE) build "CFLAGS=-Wall -pedantic -g -DDEBUG"

Any help is appreciated ;)

Thanks

pasta
  • 1,466
  • 5
  • 15
  • 25
  • Why aren't you using the system-provided `zlib1g` and `zlib1g-dev` packages? – sarnold Mar 14 '12 at 11:00
  • @sarnold: zlib1g is already installed, I was just confused with "zlib" and "zlib1g". Dont know if they are exactly the same... – pasta Mar 14 '12 at 11:05
  • Heh, that change was made back in 1998 (judging from `apt-get changelog zlib1g`) -- right around the time `libc5` was replaced with `libc6`. Maybe they're related? If your program compiles after running `apt-get install zlib1g-dev`, then you can ignore your version in `/usr/local/`. – sarnold Mar 14 '12 at 11:13
  • @sarnold I tried `apt-get install zlib1g-dev` but that doesnt compile :( – pasta Mar 14 '12 at 11:18

1 Answers1

10

I found the answer myself ! It works by changing:

$(CC) $(CFLAGS) $(LDFLAGS) $(OPT) $? -o sickle

to

$(CC) $(CFLAGS)  $(OPT) $? -o sickle $(LDFLAGS)

the -lz option has to be at the end.

pasta
  • 1,466
  • 5
  • 15
  • 25