1

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
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • 1
    to avoid the dash problem in future, use a plain text editor. Not a word processor, not a web browser, not a prettifier of any sort, just plain text. – o11c Oct 09 '14 at 00:42
  • For (2), you'll want to get in the habit of using the man pages. E.g., run `man gcc`, or search online. E.g., [gcc(1) - Linux man page](http://linux.die.net/man/1/gcc) was the first hit in a Google search for `man page gcc`. – Joshua Taylor Oct 09 '14 at 00:42
  • In most projects, there are one or more header files, probably one '.h' file for each '.c' file. However, the indicated 'make' file is missing all the header dependencies. 'all' and 'clean' are phony targets (dont actually create any file) and therefore there should be a 'phony: all clean' line in the file. note: make files are processed in the order written (unless needed otherwise) therefore, 'phony:' rules should be before the phony targets are declared. – user3629249 Oct 10 '14 at 06:59

2 Answers2

2

Is it possible that the -c is actually a EN DASH character instead of a hyphen?

The -c tells gcc to "just compile" the code and generate an object file instead of an executable. The clean target simply cleans up the working directory.

D.Shawley
  • 58,213
  • 10
  • 98
  • 113
2

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 (-).

Community
  • 1
  • 1