質問

This is my directory structure:

$ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'
   .
   |-Build
   |---Bin
   |-Include
   |-Lib
   |-Source

This is my makefile:

Gaurav@Gaurav-PC /cygdrive/d/Pizza/Build
$ pwd
/cygdrive/d/Pizza/Build

Gaurav@Gaurav-PC /cygdrive/d/Pizza/Build
$ ls
Bin  Makefile

Gaurav@Gaurav-PC /cygdrive/d/Pizza/Build
$vim Makefile

INCLUDES= ./../Include
OBJDIR= ./Bin
SRCDIR= ./../Source

vpath %.h $(INCLUDES)
vpath %.cpp $(SRCDIR)
vpath %.o $(OBJDIR)

CXX= g++
CXXFLAGS= -Wall -c -I$(INCLUDES)


OBJECTS= Pizza.o PizzaClassMain.o


Pizza: $(OBJECTS)
    $(CXX) -Wall $^ -o $(OBJDIR)/$@ 


PizzaClassMain.o:PizzaClassMain.cpp Pizza.h
    $(CXX) $(CXXFLAGS) $< -o $(OBJDIR)/$@

Pizza.o: Pizza.cpp Pizza.h
    $(CXX) $(CXXFLAGS) $< -o $(OBJDIR)/$@

.PHONY: clean

clean:
    rm -f $(OBJDIR)/*.o $(OBJDIR)/*.exe *~ .Makefile.un~ 

I am getting below error:

$ make
g++ -Wall -c -I./../Include ./../Source/Pizza.cpp -o ./Bin/Pizza.o
g++ -Wall -c -I./../Include ./../Source/PizzaClassMain.cpp -o ./Bin/PizzaClassMain.o
g++ -Wall Pizza.o PizzaClassMain.o -o ./Bin/Pizza
g++: error: Pizza.o: No such file or directory
g++: error: PizzaClassMain.o: No such file or directory
g++: fatal error: no input files
compilation terminated.
Makefile:18: recipe for target 'Pizza' failed
make: *** [Pizza] Error 1

I have put vpath %.o $(OBJDIR) in my Makefile but still rule: Pizza is not able to find Pizza.o & PizzaClassMain.o though they are being created correctly in directory ./Bin by the rules Pizza.o & PizzaClassMain.o

If I manually run g++ -Wall g++ -Wall Pizza.o PizzaClassMain.o -o Pizza from directory ./Bin then it works fine.

I am not able to figure out why the rule Pizza is not able to find input files? Can anyone please help?

PS: This Makefile did compile successfully once or twice out of say 40 times. Are there some issues with cygwin package make?

役に立ちましたか?

解決 2

Below changes in rule resolved the issue:

Pizza: $(OBJECTS)
    $(CXX) -Wall $(addprefix $(OBJDIR)/,$^) -o $(OBJDIR)/$@ 

Very nice article http://mad-scientist.net/make/vpath.html as pointed by OliCharlesworth.

他のヒント

Your objects should be:

 OBJECTS= ./Bin/Pizza.o ./Bin/PizzaClassMain.o

These objects are compiled successfully as the rule PIZZA: $(OBJECTS) finds correct rules named "Pizza.o" and "PizzaClassMain.o". These are only names of rules, not actual filenames. When Make utility looks for ./Build/Pizza.o, this file does not exist and is not found. It was created in the ./Build/Bin directory.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top