make: c: command not found

22,111

Solution 1

You need to remove the $ from the $g++ lines. It's trying to expand some variable that doesn't exist, and is swallowing up the "$g++ -" from your commands.

The syntax for using a variable is:

$(CXX) -c main.cpp

In this case, CXX is the path to the C++ compiler, which is defined for you. You can change it by adding the following line to your makefile:

CXX = g++

If you are trying to avoid echoing back the command make is running, use @ instead of $.

Solution 2

$g++ is not defined in that makefile, so the command becomes

-o MergeSort main.o MergeSort.o

and

-c main.cpp

Either drop the $ from $g++ and use g++, or define the variable in your makefile.

CXX = g++
all: MergeSort clean

MergeSort: main.o MergeSort.o
    $CXX -o MergeSort main.o MergeSort.o

main.o: main.cpp MergeSort.h
    $CXX -c main.cpp

MergeSort.o: MergeSort.cpp MergeSort.h
    $CXX -c MergeSort.cpp

clean:
    rm -rf *o

cleanall:
    rm -rf *o *exe
Share:
22,111
Matt
Author by

Matt

Updated on July 09, 2022

Comments

  • Matt
    Matt almost 2 years

    I am attempting to run my make file however i am getting the following two errors:

    make: c: command not found

    and

    make: o: command not found

    I am attempting to do this inside of cygwin. I have g++ and make installed on it, however when I run the make file I receive these errors.

    Any ideas?

    The makefile:

    all: MergeSort clean
    
    MergeSort: main.o MergeSort.o
        $g++ -o MergeSort main.o MergeSort.o
    
    main.o: main.cpp MergeSort.h
        $g++ -c main.cpp
    
    MergeSort.o: MergeSort.cpp MergeSort.h
        $g++ -c MergeSort.cpp
    
    clean:
        rm -rf *o
    
    cleanall:
        rm -rf *o *exe
    
  • Wolf
    Wolf over 4 years
    I think you should exchange $CXX by $(CXX) for GNU Make (the OP seems to ask about).