0

I'm a little new to this and am trying to build a rather large project. In particular, the source code is executing the lines

gcc -Wall -W   -c -o setitimer-helper.o setitimer-helper.c
gcc -lm  setitimer-helper.o   -o setitimer-helper

This creates a linker error because according to this C: Undefined reference to floor -lm now must come after the object files.

I need to know where in the source code I can find and rearrange this. I think it's in here, but I'm unfamiliar with Unix.

CC = gcc
CFLAGS = -Wall -W
LDFLAGS = -lm

all: setitimer-helper squish-pty squish-unix

%.o: %.c
    $(CC) -c $< -o $@

%: %.c
    $(CC) $(CFLAGS) $< $(LDFLAGS) -o $@

clean:
    rm -f *.o setitimer-helper squish-pty squish-unix

Am I correct? If so, how can I fix this. If not, where should I look?

Thanks.

Community
  • 1
  • 1
Dylan_Larkin
  • 503
  • 4
  • 15

1 Answers1

0

Change the rule to build your binary to put $(LDFLAGS) at the end.

%: %.c
    $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)

When executed the gcc command should look like.

gcc -Wall -W setitimer-helper.c -o setitimer-helper -lm
Paul Rooney
  • 20,879
  • 9
  • 40
  • 61