bash - Adding library via CFLAGS still results in link failures -


i'm trying compile program on ubuntu 12.04 on virtualbox, , 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 `clock_gettime' collect2: ld returned 1 exit status make: *** [bwc-orig] error 1 

i found out had add -lrt, i'm not sure how it, here's 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 makefile, add -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 following output (it's pretty same, except see -lrt flag @ 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 `clock_gettime' collect2: ld returned 1 exit status make: *** [bwc-orig] error 1 

i don't know how have add -lrt flag. don't know makefiles, , don't know anymore.

thanks.

edit: nevermind, solved it. after running make, , getting last output, decided run

gcc -g bwc.o jsocket6.4.o dataclient-seqn.o bufbox.o -o bwc-orig -lpthread -lrt 

and worked, because problem had add -lrt @ end.

thanks anyway.

library flags need go last. everywhere see -lpthread add -lrt (or maybe refactor variable need change 1 place if need add still more libraries).


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -