I'm trying to compile a program on Ubuntu 12.04 on VirtualBox, and I get the following error:
daniel@daniel-VirtualBox:~/Documents/Redes/t1$ make
gcc -g -c -o bwc.o bwc.c
gcc -g -c -o jsocket6.4.o jsocket6.4.c
gcc -g -c -o Dataclient-seqn.o Dataclient-seqn.c
gcc -g -c -o bufbox.o bufbox.c
gcc -g bwc.o jsocket6.4.o Dataclient-seqn.o bufbox.o -o bwc-orig -lpthread
Dataclient-seqn.o: In function `Now':
/home/daniel/Documents/Redes/t1/Dataclient-seqn.c:68: undefined reference to `clock_gettime'
collect2: ld returned 1 exit status
make: *** [bwc-orig] Error 1
I found out I had to add -lrt, but I'm not sure how to do it, here's my makefile:
CC=gcc
CFLAGS=-g # -m32
BIN=bwc-orig bwc bwc-tcp bws-tcp
all: $(BIN)
bwc-orig: bwc.o jsocket6.4.o Dataclient-seqn.o jsocket6.4.h bufbox.o
$(CC) $(CFLAGS) bwc.o jsocket6.4.o Dataclient-seqn.o bufbox.o -o $@ -lpthread
bwc: bwc.o jsocket6.4.o Dataclient-bigseq.o jsocket6.4.h bufbox.o
$(CC) $(CFLAGS) bwc.o jsocket6.4.o Dataclient-bigseq.o bufbox.o -o $@ -lpthread
bwc-tcp: bwc.o jsocket6.4.o Data-tcp.o jsocket6.4.h
$(CC) $(CFLAGS) bwc.o jsocket6.4.o Data-tcp.o -o $@ -lpthread
bws-tcp: bws.o jsocket6.4.o Data-tcp.o jsocket6.4.h
$(CC) $(CFLAGS) bws.o jsocket6.4.o Data-tcp.o -o $@ -lpthread
cleanall:
rm -f $(BIN) *.o
I modified the makefile, to add the -lrt flag:
CC=gcc
CFLAGS=-g -lrt # -m32
BIN=bwc-orig bwc bwc-tcp bws-tcp
all: $(BIN)
bwc-orig: bwc.o jsocket6.4.o Dataclient-seqn.o jsocket6.4.h bufbox.o
$(CC) $(CFLAGS) bwc.o jsocket6.4.o Dataclient-seqn.o bufbox.o -o $@ -lpthread
bwc: bwc.o jsocket6.4.o Dataclient-bigseq.o jsocket6.4.h bufbox.o
$(CC) $(CFLAGS) bwc.o jsocket6.4.o Dataclient-bigseq.o bufbox.o -o $@ -lpthread
bwc-tcp: bwc.o jsocket6.4.o Data-tcp.o jsocket6.4.h
$(CC) $(CFLAGS) bwc.o jsocket6.4.o Data-tcp.o -o $@ -lpthread
bws-tcp: bws.o jsocket6.4.o Data-tcp.o jsocket6.4.h
$(CC) $(CFLAGS) bws.o jsocket6.4.o Data-tcp.o -o $@ -lpthread
cleanall:
rm -f $(BIN) *.o
But I get the following output (it's pretty much the same, except I see the -lrt flag at the beggining):
daniel@daniel-VirtualBox:~/Documents/Redes/t1$ make
gcc -g -lrt -c -o bwc.o bwc.c
gcc -g -lrt -c -o jsocket6.4.o jsocket6.4.c
gcc -g -lrt -c -o Dataclient-seqn.o Dataclient-seqn.c
gcc -g -lrt -c -o bufbox.o bufbox.c
gcc -g -lrt bwc.o jsocket6.4.o Dataclient-seqn.o bufbox.o -o bwc-orig -lpthread
Dataclient-seqn.o: In function `Now':
/home/daniel/Documents/Redes/t1/Dataclient-seqn.c:76: undefined reference to `clock_gettime'
collect2: ld returned 1 exit status
make: *** [bwc-orig] Error 1
I don't know how I have to add the -lrt flag. I actually don't know so much about makefiles, and don't know what to do anymore.
Thanks.
EDIT: Nevermind, I just solved it. After running make, and getting that last output, I just decided to run
gcc -g bwc.o jsocket6.4.o Dataclient-seqn.o bufbox.o -o bwc-orig -lpthread -lrt
And it worked, because the problem was I had to add -lrt at the end.
Thanks anyway.