• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4046
  • Last Modified:

Makefile question. "No rule to make target..."

If I have a makefile rule like:

myprog.o : myprog.cpp
    g++ -g -Wall -c myprog.cpp

Why does make say:
"make:  *** No rule to make target `myprog.cpp', needed by `myprog.o'.  Stop."

How do you set up a rule to make a cpp file?
0
lwinkenb
Asked:
lwinkenb
  • 2
2 Solutions
 
smidgie82Commented:
Hi lwinkenb,

Unless you're using a code generator such as lex or yacc (or flex or bison), of course, you shouldn't have to have a rule to make a cpp file.  make should automatically discover that the dependency as specified references a file, not a rule.  The short answer is that myprog.cpp most likely isn't visible in make's search path from wherever you're calling it.  Or at least that's how I just duplicated the error you posted.


Cheers!
0
 
lwinkenbAuthor Commented:
well I do have a directory structure like:

Makefile
Sources (directory)
Include (directory)

How do I tell the Makefile that the source files are in the Sources directory.
0
 
manish_regmiCommented:
all:
    make -C Sources

this will get you inside the Sources directory and the makefile in that directory will run


regards
Manish Regmi
0
 
manish_regmiCommented:
then in the sources directory you can do

INCL = -I. -I../ -I../Include
OPTIONS = -Wall -O2

all:
.c.o:
      $(CC) -c $(OPTIONS) $(INCL) $< -o $@


regards
Manish Regmi
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now