Berkin
Berkin

Reputation: 1664

Makefile error in C with same function

I want use "Makefile" in my project which im working on socket programming. I have two simple .c files but they have their own main function. And makefile returns an error because of these two main functions.

I have one main function in server.c file and one main function in client.c

ERROR

gcc server.o client.o -o output -lpthread client.o: In function main': client.c:(.text+0x0):main' için birden fazla tanım server.o:server.c:(.text+0x78): ilk burada tanımlanmış collect2: error: ld returned 1 exit status Makefile:4: recipe for target 'output' failed make: *** [output] Error 1

MAKEFILE

all: output

output: server.o client.o
    gcc server.o client.o -o output -lpthread

server.o: server.c
    gcc -c server.c

client.o: client.c
    gcc -c client.c

clean:
    rm *.o

Thanks :)

Upvotes: 0

Views: 241

Answers (1)

negacao
negacao

Reputation: 1274

It won't work like that. You'll need two outputs, ala

all: server client

server: server.o
    gcc server.o -o server -lpthread

client: client.o
    gcc client.o -o client -lpthread

This is because your program can only have one main. What are you trying to do that you want to compile both .c files into one executable?

Upvotes: 1

Related Questions