newb: what is wrong with my makefile?

user3064406

I have a makefile, provided at the end, and a few questions about it:

  1. What does the clean: part do?
  2. What does the -c part mean? (A Google search for gcc -c explained and other variations gives me a college with the acronym GCC.)
  3. When I try to run make, I get this error, but the file lab3p2.c definitely exists. What is wrong?

    gcc –c lab3p2.c
    gcc: –c: No such file or directory
    make: *** [lab3p2.o] Error 1 
    

Makefile

all: lab3p2

lab3p2: lab3p2.o lab3p2f1.o lab3p2f2.o lab3p2f3.o
    gcc lab3p2.o lab3p2f1.o lab3p2f2.o lab3p2f3.o –o lab3p2

lab3p2.o: lab3p2.c
    gcc –c lab3p2.c

lab3p2f1.o: lab3p2f1.c
    gcc –c lab3p2f1.c

lab3p2f2.o: lab3p2f2.c
    gcc –c lab3p2f2.c

lab3p2f3.o: lab3p2f3.c
    gcc –c lab3p2f3.c

clean:
    rm –rf  *.o  lab3p2
Tim Cooper

what does the "clean:" part do?

The clean rule of a Makefile is often used to delete any compiled files generated by the Makefile. In this case, the compiled object files (.o files) and the lab3p2 file are deleted.

Since clean is not a file that is generated, it should be made a phony rule:

clean:
    rm –rf  *.o  lab3p2

.PHONY: clean

what does the "-c" part mean? (google search "gcc -c explained" and other variations gives me a college with the acronym gcc, blah)

It means compile the source file, but don't run the linker. From the man page:

-c  Compile or assemble the source files, but do not link.  The linking stage
    simply is not done.  The ultimate output is in the form of an object file
    for each source file.

I get this error:

gcc –c lab3p2.c
gcc: –c: No such file or directory
make: *** [lab3p2.o] Error 1 

is an en dash, where it should be a hyphen-minus (-).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related