0

After going through the LWIP documents, I wrote a simple tcp echo server code. To compile it and create an executable I wrote the following Makefile. Now, when I run the command make all, it gives error for each of .c files included in the makefile.
The file structure is as follows: 1. tcp_server.c is the main file where I create the tcp server. 2. It uses the tcp_new(), tcp_bind() etc functions defined in "lwip-1.4.1/src/core/lwip/tcp.c" and "lwip-1.4.1/src/core/lwip/tcp_out.c" and I have given the paths for compilation accordingly.

I am just a beginner in writing makefiles and have written the following file going through the GNU Make documentation.

CC=gcc

CFLAGS= -g -Wall

LWIPDIR=../lwip-1.4.1/src

TARGET=tcp_server

INCLUDES= -I../lwip-1.4.1/src/include -I../STABLE-1_4_0/ports/unix/proj/lib\
        -I../STABLE-1_4_0/ports/unix/include -I../lwip-1.4.1/src/include/ipv4

LFLAGS= -L../STABLE-1_4_0/ports/unix/proj/lib/liblwip.so

#LIBS= -llwip

COREFILES=$(LWIPDIR)/core/tcp.c $(LWIPDIR)/core/tcp_out.c

VPATH = $(LWIPDIR)/core

OBJS = tcp_server.o tcp.o tcp_out.o

MAIN=tcp_server

all : edit

edit : $(OBJS)
        $(CC) $(CFLAGS) $(INCLUDES) -o edit $(OBJS) $(LFLAGS)

tcp_server.o : tcp_server.c tcp.o tcp_out.o
        $(CC) $(CFLAGS) $(INCLUDES) -c tcp_server.c $(LFLAGS)

tcp.o : $(LWIPDIR)/core/tcp.c
        $(CC) $(CFLAGS) $(INCLUDES) -c $(LWIPDIR)/core/tcp.c $(LFLAGS)

tcp_out.o : $(LWIPDIR)/core/tcp_out.c
        $(CC) $(CFLAGS) $(INCLUDES) -c $(LWIPDIR)/core/tcp_out.c  $(LFLAGS)

clean :
        rm -f *.o

All the files include certain headers defined in "lwip-1.4.1/src/include" and I given the arguments to -I accordingly. However on running make, the output shows "Undefined reference to" all the functions which are defined in the lwip header files. What could be the reason? Where I am going wrong?

Thank you for all the help.

2
  • Try using the absolute address of the include files rather than the relative address of the include files for ${INCLUDES} Jan 11, 2016 at 15:12
  • @sabbahillel have done that, but to no avail. Isn't there any visible error in the syntax or logic of the Makefile?
    – codeahead
    Jan 11, 2016 at 15:28

1 Answer 1

2

UNDEFINED REFERENCE is a linker error so you should;

For gcc you should use -L to specify the directory your libraries are contained and use -l to link a particular library. For example change the line in your makefile;

LFLAGS= -L../STABLE-1_4_0/ports/unix/proj/lib

remove the comment before LIBS and change this target

edit : $(OBJS)
        $(CC) $(CFLAGS) $(INCLUDES) -o edit $(OBJS) $(LFLAGS) $(LIBS)
2
  • The lwip.so file is in the LFLAGS path, so do I again need to give the path for the lwip.so file or it would know, from the LFLAGS, where to look for the lwip.so file?
    – codeahead
    Jan 11, 2016 at 15:30
  • it will look in the directory supplied by -L for the file liblwip.so when you specify -llwip
    – cleblanc
    Jan 11, 2016 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.