c - What is missing in my makefile? -
i trying create first makefile. tested program using following commands:
command 1: gcc -wall -ggdb3 -std=c99 -o file1 file1.c -lm -lpthread -l command 2: gcc -wall -ggdb3 -std=c99 -o file2 file2.c -lm -lpthread
everything works great. created makefile (please see below). keep getting error message. can take @ code , give me hint on problem is?
file2.o: in function `seed_primes': file2.c:(.text+0x461): undefined reference `sqrt' file2.c:(.text+0x466): undefined reference `sqrt' file2:(.text+0x533): undefined reference `sqrt' file2.o: in function `create_threads': file2.c:(.text+0x668): undefined reference `pthread_create' file2.c:(.text+0x6b5): undefined reference `pthread_join' file2.o: in function `next_seed': file2.c:(.text+0x860): undefined reference `sqrt' collect2: ld returned 1 exit status make: *** [file2] error 1
here makefile:
cc=gcc debug=-ggdb3 cflags=#(debug) -wall -lm -lpthread -lrt -l progs=file1 file2 all: $(progs) file1: file1.o $(cc) $(cflags) -o file1 file1.o file1.o: file1.c $(cc) $(cflags) -c file1.c file2: file2.o $(cc) $(cflags) -o file2 file2.o file2.o: file2.c $(cc) $(cflags) -c file2.c clean: rm -f $(progs) *.o *~
you've set cflags empty string because of #
comment character (you intended use $
instead).
you should not set libraries cflags
; belong in ldlibs
.
you don't need file1:
rule, file2:
rule, or object file rules.
cc = gcc debug = -ggdb3 cflags = $(debug) -wall ldlibs = -lm -lpthread -lrt -l progs = file1 file2 all: $(progs) clean: rm -f $(progs) *.o *~
nb: ldlibs
, related ldflags
not 100% uniform across variants of make
. ldflags
should used library paths; ldlibs
library names (-lxyz
etc).
if need different libraries 2 programs, need create separate build rules (as had originally), or use conditional macro assignments (gnu make
).
Comments
Post a Comment