DanY42
DanY42

Reputation: 23

Getting makefile to change output executable name

I am writing a makefile for a school assignment and am having some issues. I can't seem to get the output executable to be named what I want using the -o flag. Instead it is creating an executable named a.out (which is functioning properly).

When I use the "make clean" command, it tells me that my executable name that I want does not exist. I am confused with how the "make" command isn't recognizing the program name and the "make clean" command is. Any feedback would be appreciated.

 PROGRAM = osuSystem
 CXX = g++
 CXXFLAGS = -std=c++0x

 SOURCES = $(wildcard *.cpp)
 OBJECTS = $(SOURCES:.cpp=.o)
 HEADERS = $(wildcard *.hpp)

 default: ${OBJECTS}
       ${CXX} ${CXXFLAGS} ${OBJECTS} ${HEADERS] ${SOURCES} -o ${PROGRAM}

 clean:
       rm ${OBJECTS} ${PROGRAM}

Upvotes: 2

Views: 5121

Answers (1)

Tony Delroy
Tony Delroy

Reputation: 106096

Your default: ${OBJECTS} line tells make to compile all your sources into .o files, so the next line need only link the .os and shouldn't mention the source files:

default: ${OBJECTS}
        ${CXX} ${CXXFLAGS} ${OBJECTS} -o ${PROGRAM}

I reproduced your problem locally and this change got it working. For clean, you should use rm -f so it doesn't complain and removes those that do exist when you run clean while some of the objects/program to delete don't exist.

Upvotes: 1

Related Questions