10

After compiling several *.c and *.h files using make, I cleaned up the object files using make clean. However I don't know how to remove the executable.

my makefile code -->

    CC=gcc
    CFLAGS=-I.
    mp1: main.o downloader.o json.o
            $(CC) -o mp1 main.o downloader.o json.o -I.
    .PHONY : clean
    clean :
           -rm *.o $(objects)                              

3 Answers 3

7

Your executable seems to be the file mp1. Add this file to the rm command in the clean target:

clean :
       -rm *.o $(objects) mp1
5
$ sudo make clean

The above mentioned command will clean all the .o files

2
  • it would clean all and not only the .o files right?
    – anand mbs
    Commented Jun 29, 2016 at 5:01
  • 3
    -1 No, in the current state of the Makefile make clean will run rm *.o $(objects), which doesn't clean the executable (assuming that the executable is mp1 and not in $(objects)). Commented Jun 29, 2016 at 5:15
-2

This command is useful when make is not available in your system.

$ find coding/ -type f -executable | xargs rm

This command removes all executable files in the coding directory.

The first part of the command, the find part lists all the files which are executable.

The second part of the command takes the input from 1st part and gives it to rm command.

xargs - a command that converts its standard input into arguments of another program, look the man page for more info

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .