0

I have tried to make a makefile from a template and this is what I've got:

CFLAGS = -Wall -pedantic
LFLAGS = -lpthread
CC = gcc
OBJS = bank5.o client2.o
PROGRAM = ex2

all: bank client

ex2: $(OBJS)
    $(CC) $(LFLAGS) $(OBJS) -o $(PROGRAM)

bank: bank5.c
    $(CC) $(CFLAGS) -c bank5.c receive_message.c send_message.c -o bank5

client: client2.c
    $(CC) $(CFLAGS) -c client2.c receive_message.c send_message.c -o client2

When I try to run it I get this error:

gcc -Wall -pedantic -c bank5.c receive_message.c send_message.c -o bank5
gcc: fatal error: cannot specify -o with -c, -S or -E with multiple files
compilation terminated.
make: *** [bank] Error 4

This is what my makefile looked like before -Wall and -pedantic, this ran normally:

all: bank client

bank: bank5.c
    gcc bank5.c receive_message.c send_message.c -o bank5 -lpthread

client: client2.c
    gcc -o client2 client2.c send_message.c receive_message.c
0

1 Answer 1

1
  • -c will just compile each file (i.e., produce an object file), not link them together. Because one object file corresponds to one source file, multiple object files will be created.

  • -o specifies one output file.

Obviously, both contradict each other.

Remove the -c to fix the problem.


Anyway, your makefile looks broken. What does ex2 do there? bank5.o and client2.o are nowhere created.

1
  • Like I said, I was doing it from a template and the template had those.
    – Mari
    Dec 5, 2015 at 21:45

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.