andandandand
andandandand

Reputation: 22270

Is this makefile eliminating the .c file?

all: servidor
servidor: servidor.o
    gcc -lpthread -o servidor.o
servidor.o:
clean:
    gcc -c servidor.c
    rm -rf servidor.o

Questions:

a)Is the clean: line eliminating the servidor.c file?

b)How can I modify the makefile so that it also compiles a client.c program and creates a client.o?

Upvotes: 0

Views: 260

Answers (3)

Alex Brown
Alex Brown

Reputation: 42912

Your entire makefile should look like this:

LDLIBS=-lpthread
servidor: servidor.o client.o
clean:
<TAB>rm -f *.o

Upvotes: 2

Kevin
Kevin

Reputation: 11

the makefile seems so strange,i am not sue whether it can work or not? but i think it better as following:

    all: client
client: client.o
    gcc -lpthread -o client.o
client.o:
    gcc -c client.c
clean: 
    rm -rf client.o

Upvotes: 0

jpalecek
jpalecek

Reputation: 47770

a)Is the clean: line eliminating the servidor.c file?

No. The line

gcc -c servidor.c

is just a lame way of ensuring servidor.o exists, and the subsequent rm does not fail. It should rather be

clean:
    -rm -rf servidor.o

b)How can I modify the makefile so that it also compiles a client.c program and creates a client.o?

The easiest way is use built-in rules. If you add client, or client.o in any of a rule's prerequisites, it will be built automatically from client.c.

(and add -lpthread to LDLIBS if you need it for client.c)

Upvotes: 0

Related Questions