I am beginner when it comes to writing makefiles but I am having this linking issue with my program. Basically I am getting the above error when I try to build it on a remote machine.
Here is my makefile:
SRCS = gt_cfs.c gt_kthread.c gt_matrix.c gt_pq.c gt_signal.c gt_spinlock.c \
gt_uthread.c red_black_tree.c stack.c misc.c
HDRS = gt_bitops.h gt_cfs.h gt_include.h gt_kthread.h gt_pq.h gt_signal.h \
gt_tailq.h gt_uthread.h red_black_tree.h stack.h misc.h
OBJS = gt_cfs.o gt_kthread.o gt_matrix.o gt_pq.o gt_signal.o gt_spinlock.o \
gt_uthread.o red_black_tree.o stack.o misc.o
CC = gcc
CFLAGS = -Wall -pedantic -lrt -lm
PROGRAM = cfs_gtthreads
.PHONY: clean
all: $(PROGRAM)
$(PROGRAM): $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $(PROGRAM)
gt_include.h: gt_bitops.h gt_cfs.h gt_kthread.h gt_pq.h \
gt_signal.h gt_tailq.h gt_uthread.h
gt_cfs.o: gt_cfs.c
gt_kthread.o: gt_kthread.c
gt_matrix.o: gt_matrix.c
gt_pq.o: gt_pq.c
gt_signal.o: gt_signal.c
gt_spinlock.o: gt_spinlock.c
gt_uthread.o: gt_uthread.c
red_black_tree.o: red_black_tree.c
stack.o: stack.c
clean:
rm -f *.o *~ $(PROGRAM)
Now this code WORKS on my laptop but I have to run my program on a remote machine through SSH. Anyway on that machine is where I get this error, so I am confused as to why it can’t link the two libraries: math and time (-lm and -lrt). The gcc versions are different, mine is 4.5.2 and the cluster machine is 4.1.2. I am also running mine on Ubuntu and the cluster machine is Red-Hat. I don’t know what differences would cause this error since those are standard libraries. Any help is appreciated.
Thanks in advance.
Try using a
LDFLAGSvariable with-lrt -lmand put$(LDFLAGS)after the$(OBJS).