简体   繁体   中英

makefile cant find .o files

I'm very new to make files but after looking through a bunch of sources I cant find out why my make file is not working, it is for C++ and stated as below.

CC=g++
CFLAGS=-g -Wall -pedantic -ansi
SOURCES=commercial.cpp comRentals.cpp comSales.cpp property.cpp rentals.cpp residential.cpp resRentals.cpp resSales.cpp sales.cpp testPropertyA.cpp utility1.cpp
OBJECTS=$(SOURCES:.cpp=.o)
TARGET = runme

all: $(TARGET)

$(TARGET): $(OBJECTS) 
    $(CC) $(CFLAGS) -o $(TARGET) $(OBJECTS)

.cpp.o:
    $(CC) $(CFLAGS) -c $< -o $@

.PHONY: clean
clean:
    -del $(OBJECTS) $(TARGET).exe

It is constantly saying the following when run from windows 7 commandline

C:\Users\Stat Phantom\Desktop\UNIVERSITY\C++\Assignment1\StartUpCode\TaskA>make
g++ -g -Wall -pedantic -ansi -c commercial.cpp -o commercial.o
process_begin: CreateProcess(NULL, g++ -g -Wall -pedantic -ansi -c commercial.cp
p -o commercial.o, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [commercial.o] Error 2

no idea what is happening here, help please, it is probably something very simple.

UPDATE: removed the included tags and added $@ to .cpp.o: however same error is occuring

You need to specify output file name after -o :

Replace this:

.cpp.o:
    $(CC) $(CFLAGS) $(INCLUDES) -c $< -o

with this:

.cpp.o:
    $(CC) $(CFLAGS) -c $< -o $@

Note: $(INCLUDES) also need to be removed.

EDIT: After further checking, the actual issue seems to be simply because the OP does not have g++ installed. The relevant answer is available in this other SO question: Compiling Small Gcc Project on Windows Using MinGW

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM