-1

I'm attempting to do an assignment which utilizes a "makefile", a "readme", and also a C++ source program (.cpp file) and all of this should be in a compressed tar file. I was told that my makefile should have a clean and backup rule also, I don't know how to do the rest properly.

I attempted to turn in my assignment but I was told "Your makefile does not have a default rule that compiles this program."

This is my makefile:

# makefile to build a program
clean:
    /bin/rm -f myname *.o
backup:
    tar czf cm25.assignment4_1.tar.gz readme Makefile

Obviously I am missing something but here's an old makefile from an old assignment that can be used as reference but I don't know what I need to include and don't need to include:

# makefile to build a program

# program depends on components: name and main 
myname:      main.o name.o 
    g++ -g  main.o name.o -o myname

# name.cpp has it's own header file
name.o:        name.cpp name.h
    g++ -c -g  name.cpp

# main.cpp also uses the header file name.h
main.o:        main.cpp name.h
    g++ -c -g main.cpp

clean:
    /bin/rm -f myname *.o
backup:
    tar czf cm25.assignment4_1.tar.gz *.cpp readme Makefile

All my compressed tar file has is a single .cpp file, a readme and a makefile, I don't have headers or anything.

2

I attempted to turn in my assignment but I was told "Your makefile does not have a default rule that compiles this program."

Well, whoever said that is right: you have only two rules, one that removes build products and one that archives part of your project (not including the actual source code).

Add, to the beginning of the Makefile:

all: myprogram

And to the end:

myprogram: myprogram.cpp
(TAB)gcc -Os -Werror -Wall -Wextra -o myprogram myprogram.cpp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.