0

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?

martin
  • 1,707
  • 6
  • 34
  • 62
  • 2
    As shown in the question marked as duplicate, your LDFLAGS is in the wrong place. It should at least come *after* the .o files. – nos Nov 28 '14 at 23:45
  • `$(CC) test.o $(LDFLAGS) -o test` works. Thank you! But I still don't know what params are for linker/compiler. – martin Nov 28 '14 at 23:50
  • I don't know what you mean by that – nos Nov 28 '14 at 23:51
  • For example: `-L/usr/lib/modbus` is for `LDFLAGS` or `CFLAGS`? – martin Nov 29 '14 at 00:01
  • -L specifies where to search for libraries, libraries are used at the linking stage, so you'll need that in LDFLAGS – nos Nov 29 '14 at 00:04

0 Answers0