LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   error in Makefile (https://www.linuxquestions.org/questions/programming-9/error-in-makefile-633023/)

lrios 04-04-2008 11:03 AM

error in Makefile
 
Hi everyone
Iam doing something wrong with my Makefile. I have 2 executables server and client, 1 header network.h and network.c. When i write $make all it doesn't find network.c the but it works when i write $ gcc -o server server.c network.c -lpthread.
What are i doing wrong in TARGETS ??:( HEADER can i deleted ??

Code:

CFLAGS = -Wall -g
CC = gcc
TARGETS = server client network.o
LDLIBS = -lpthread
HEADER = network.h


all:        $(TARGETS)
        $(CC) -o $@ $^ $(LDLIBS) $(CFLAGS)
        @echo Server && Client OK       


server:        server.c
        $(CC) -o $@ $^ $(LDLIBS) $(CFLAGS)


client:        client.c
        $(CC) -o $@ $^ $(LDLIBS) $(CFLAGS)


network.o:        network.c network.h
        gcc -c network.c


clean:
        @echo Cleaning
        rm -f $(TARGETS) *.o *.~ *.out *.c~
        @echo OK.

.PHONY:        clean


BrianK 04-04-2008 12:51 PM

What is the exact error message you're getting?

ntubski 04-04-2008 07:44 PM

Code:

all:        $(TARGETS)
        $(CC) -o $@ $^ $(LDLIBS) $(CFLAGS)
        @echo Server && Client OK

$@ expands to the name of the target, so the second line causes gcc to make an executable called "all". I don't think you need this line at all.

&& is a shell operator, so the last line echo's "Server", then tries to execute a command called Client, you should write
Code:

@echo "Server && Client OK"
  or
@echo Server and Client OK



All times are GMT -5. The time now is 10:37 PM.