make command with math library

245 views Asked by At

I need to just run the make command for makefile. But when I run this make command I get the error that "undefined reference to `log'" because I know this fact that it doesn't include math Library and we have to include at runtime. I know that if I run this using gcc comiler then i can write -lm at the end, it will include math library. My problem is I need to run it using make command that is- make lu.

In this if I write make lu -lm it is not linking math library. Please help

Using this link How to use LDFLAGS in makefile I updated my make file but still same problem persists. Please Help.

SHELL=/bin/sh
BENCHMARK=ep
BENCHMARKU=EP

include ../config/make.def

OBJS = ep.o ${COMMON}/c_print_results.o ${COMMON}/c_${RAND}.o \
       ${COMMON}/c_timers.o ${COMMON}/c_wtime.o

include ../sys/make.common
LDLIBS=-lm
LDFLAGS=-lm


${PROGRAM}: config ${OBJS}
    ${CLINK} ${CLINKFLAGS} -o ${PROGRAM} $(LDFLAGS) $(LOADLIBES) ${OBJS} ${C_LIB}


ep.o:       ep.c npbparams.h
    ${CCOMPILE} ep.c

clean:
    - rm -f *.o *~ 
    - rm -f npbparams.h core
1

There are 1 answers

1
MadScientist On

Why does your makefile refer to all sorts of variables that don't exist, like LOADLIBES, C_LIB? Why do you set variables that you never use, like LDLIBS?

The reason it doesn't work is that you're putting the library reference in the LDFLAGS variable, which comes early in your link command before any of your object files. So when the linker goes to link in the math library it thinks that it's not needed because nothing is using it yet.

You have to put libraries at the end of the link line.

Since you already have the C_LIB variable at the end which you are not using, if you add:

C_LIB = -lm

then it should work.