cgccmakefilegcc-pedantic

gcc makefile with -Wall -pedantic and -lpthread


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

Solution

  • 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.