C create Makefile: how to set CFLAGS and LDFLAGS

90 views Asked by At

I have simple modbus master project written in C99 C. Now I am compiling my application using (it works good):

$ gcc -std=c99 -O2 -Wall -I/usr/include/modbus test.c -o test -L/usr/lib/modbus -L/usr/include/curl -lmodbus -lm -lcurl

I would like to write classic Makefile. I try this:

CFLAGS=-std=c99 -O2 -Wall -I/usr/include/modbus 
LDFLAGS=-L/usr/lib/modbus -L/usr/include/curl -lmodbus -lm -lcurl

test: test.o
    $(CC) $(LDFLAGS) test.o -o test
test.o: test.c
    $(CC) $(CFLAGS) -c test.c

clean:
    rm *.o test

but if I run make it crash on:

cc -L/usr/lib/modbus -L/usr/include/curl -lmodbus -lm -lcurl test.o -o test
test.o: In function `myFunction':
test.c:(.text+0x80): undefined reference to `log'

Where I have an error? What differences are between CFLAGS and LDFLAGS? CFLAGS is for compiler and LDFLAGSis for linker? How can I determine from my first gcc command what is param for compiler and which is for linker?

0

There are 0 answers