b5er b5er - 1 month ago 12
C Question

Makefile in C, get an error

This is my Makefile:

CC = gcc

CFLAGS = -c -ansi -pedantic-errors -Wall -Werror -Wshadow -Wwrite-strings

all: fs-sim.x

fs-sim.x: fs-sim.o public01.o public02.o public03.o public04.o public05.o public06.o public07.o public08.o public09.o public10.o
$(CC) fs-sim.o public01.o public02.o public03.o public04.o public05.o public06.o public07.o public08.o public09.o public10.o -o fs-sim.x

fs-sim.o: fs-sim.c fs-sim-datastructure.h fs-sim.h
$(CC) $(CFLAGS) fs-sim.c

public01.o: public01.c
$(CC) $(CFLAGS) public01.c

public01.x: public01.o fs-sim.o
$(CC) public01.c fs-sim.o -o public01.x

public02.o: public02.c
$(CC) $(CFLAGS) public02.c

public02.x: public02.o fs-sim.o
$(CC) public02.o fs-sim.o -o public02.x

public03.o: public03.c memory-checking.h
$(CC) $(CFLAGS) public03.c

public03.x: public03.o fs-sim.o memory-checking.o
$(CC) public03.o fs-sim.o memory-checking.o -o public03.x

public04.o: public04.c memory-checking.h
$(CC) $(CFLAGS) public04.c

public04.x: public04.o fs-sim.o memory-checking.o
$(CC) public04.o fs-sim.o memory-checking.o -o public04.x

public05.o: public05.c driver.h memory-checking.h
$(CC) $(CFLAGS) public05.c

public05.x: public05.o fs-sim.o memory-checking.o
$(CC) public05.o fs-sim.o memory-checking.o -o public05.x

pubilc06.o: public06.c
$(CC) $(CFLAGS) public06.c

public06.x: public06.o fs-sim.o
$(CC) public06.o fs-sim.o -o public06.x

public07.o: public07.c
$(CC) $(CFLAGS) public07.c

public07.x: public07.o fs-sim.o
$(CC) public07.o fs-sim.o -o public07.x

public08.o: public08.c
$(CC) $(CFLAGS) public08.c

public08.x: public08.o fs-sim.o
$(CC) public08.o fs-sim.o -o public08.x

public09.o: public09.c driver.h
$(CC) $(CFLAGS) public09.c

public09.x: public09.o fs-sim.o driver.o
$(CC) public09.o fs-sim.o driver.o -o public09.x

public10.o: public10.c driver.h
$(CC) $(CFLAGS) public10.c

public10.x: public10.o fs-sim.o driver.o
$(CC) public10.o fs-sim.o driver.o -o public10.x





clean:
rm public01.o public01.x public02.o public02.x public03.o public03.x public04.o public04.x public05.o
public05.x public06.o public06.x public07.o public07.x public08.o public08.x public09.o public09.x
public10.o public10.x fs-sim.o fs-sim.x


And is giving me this error on the terminal:

gcc -c -ansi -pedantic-errors -Wall -Werror -Wshadow -Wwrite-strings public01.c
gcc -c -ansi -pedantic-errors -Wall -Werror -Wshadow -Wwrite-strings public02.c
gcc -c -ansi -pedantic-errors -Wall -Werror -Wshadow -Wwrite-strings public03.c
gcc -c -ansi -pedantic-errors -Wall -Werror -Wshadow -Wwrite-strings public04.c
gcc -c -ansi -pedantic-errors -Wall -Werror -Wshadow -Wwrite-strings public05.c
gcc fs-sim.o public01.o public02.o public03.o public04.o public05.o public06.o public07.o public08.o public09.o public10.o -o fs-sim.x
public02.o: In function `main':
public02.c:(.text+0x0): multiple definition of `main'
public01.o:public01.c:(.text+0x0): first defined here
public03.o: In function `main':
public03.c:(.text+0x0): multiple definition of `main'
public01.o:public01.c:(.text+0x0): first defined here
public04.o: In function `main':
public04.c:(.text+0x0): multiple definition of `main'
public01.o:public01.c:(.text+0x0): first defined here
public05.o: In function `main':
public05.c:(.text+0x0): multiple definition of `main'
public01.o:public01.c:(.text+0x0): first defined here
public06.o: In function `main':
public06.c:(.text+0x0): multiple definition of `main'
public01.o:public01.c:(.text+0x0): first defined here
public07.o: In function `main':
public07.c:(.text+0x0): multiple definition of `main'
public01.o:public01.c:(.text+0x0): first defined here
public08.o: In function `main':
public08.c:(.text+0x0): multiple definition of `main'
public01.o:public01.c:(.text+0x0): first defined here
public09.o: In function `main':
public09.c:(.text+0x0): multiple definition of `main'
public01.o:public01.c:(.text+0x0): first defined here
public10.o: In function `main':
public10.c:(.text+0x0): multiple definition of `main'
public01.o:public01.c:(.text+0x0): first defined here
public03.o: In function `main':
public03.c:(.text+0x9): undefined reference to `setup_memory_checking'
public03.c:(.text+0x8c): undefined reference to `check_heap'
public04.o: In function `main':
public04.c:(.text+0x9): undefined reference to `setup_memory_checking'
public04.c:(.text+0x8c): undefined reference to `check_heap'
public05.o: In function `main':
public05.c:(.text+0x9): undefined reference to `setup_memory_checking'
public05.c:(.text+0x15): undefined reference to `driver'
public05.c:(.text+0x26): undefined reference to `check_heap'
public09.o: In function `main':
public09.c:(.text+0x10): undefined reference to `driver'
public10.o: In function `main':
public10.c:(.text+0x10): undefined reference to `driver'
collect2: ld returned 1 exit status
make: *** [fs-sim.x] Error 1


How do you fix this error? I've been look all around, and can't find the answer yet. I have tried changing the header files around, as well. Any help will be greatly appreacited; if you need more information about my file, let me know.

Solution:

fs-sim.x: public01.x public02.x public03.x public04.x public05.x public06.x
public07.x public08.x public09.x public10.x

Answer

at link time:

in all the sum of the files that are included in a link operation, there can be only one(1) main() function.

Per your own comment, each of the files public??.c contains a main() function.

From each of the public??.c files leading to several executables, the first thing (I suggest) is not to link more that one public??.c file into any single executable file.

Per the output from the link statement, there are three data objects are are not actually defined.

Exactly what are you expecting the final result (list of file names) to contain?

how many executables are you expecting to be produced?

The answers to the above questions need to be part of the question, Then we can give you a much more comprehensive answer to your question as to what is wrong with the posted makefile .