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?
LVL 5
lwinkenbAsked:
Who is Participating?
 
smidgie82Connect With a Mentor Commented:
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_regmiConnect With a Mentor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.