-4

There are 3 files : "client.c" , "server.c" and "util.h"

I need to compile this with gcc on linux and have 2 executables, 1 for client and another for server . But it can be possible to have more than 1 client running and ONLY 1 server. Im not sure how to do this , create 1 makefile only for client and another for server or just 1 and it can work ?

Kelve
  • 137
  • 2
  • 14
  • Create multiple targets `client: client.c util.h`, `server: server.c util.h`, and then `all: client server`. It would also help if you rewrite your question, because it is not really comprehensible right now. – Pablo Jan 15 '18 at 11:08
  • You create a `Makefile` with a [source code editor](https://en.wikipedia.org/wiki/Source_code_editor) understanding tabs. I prefer [GNU emacs](https://www.gnu.org/software/emacs/). Your question is off-topic on SO. You run your programs in a terminal (or thru the `gdb` debugger) and you might open several terminal windows. See [this example](https://stackoverflow.com/a/16751650/841108) of `Makefile` – Basile Starynkevitch Jan 15 '18 at 11:16

1 Answers1

4

There is only one Makefile to create:

TARGET=client server 
normal: $(TARGET)
client: client.c
    gcc -Wall client.c -o client
server: server.c
    gcc -Wall server.c -o server
clean:
    $(RM) $(TARGET) 

It will create 2 executables (server and client) to run. Execute the server once simultanously with one/multiple client(s).

[Edit] I was advised an improved solution:

TARGET=client server 
CC=gcc
CFLAGS= -Wall -Wextra -g
normal: $(TARGET)
client: client.c
    $(CC) $(CFLAGS) client.c -o client
server: server.c
    $(CC) $(CFLAGS) server.c -o server
clean:
    $(RM) $(TARGET)
Dixel
  • 516
  • 1
  • 4
  • 9