Make implicit rules and header files - Unix

This is a discussion on Make implicit rules and header files - Unix ; I'm trying to use an implicit rule to compile all my .cpp files. I want the .o files to depend on the .cpp file and the .h file. All the examples I've seen for defining an implicit rule look something ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Make implicit rules and header files

  1. Make implicit rules and header files

    I'm trying to use an implicit rule to compile all my .cpp files. I
    want the .o files to depend on the .cpp file and the .h file. All the
    examples I've seen for defining an implicit rule look something like
    this:

    %.o : %.cpp
    c++ -c $<

    But I'm trying to do something like this:

    %.o : %.cpp %.h
    c++ -c $<

    This seems isn't working like I expect. Is there a different way to
    do this?

  2. Re: Make implicit rules and header files

    jordanphulet@gmail.com wrote:
    > I'm trying to use an implicit rule to compile all my .cpp files. I
    > want the .o files to depend on the .cpp file and the .h file. All the
    > examples I've seen for defining an implicit rule look something like
    > this:


    > %.o : %.cpp
    > c++ -c $<


    > But I'm trying to do something like this:


    > %.o : %.cpp %.h
    > c++ -c $<


    > This seems isn't working like I expect. Is there a different way to
    > do this?


    This is a bit difficult to anser since just write "isn't working
    as I expect" and "different way to this" but you don't tell what
    your expectations are. For me this works perfectly well, i.e. it
    compiles e.g. x.cpp to x.o if x.cpp or x.h are newer than x.o
    when invoked with "make x.o".
    Regards, Jens
    --
    \ Jens Thoms Toerring ___ jt@toerring.de
    \__________________________ http://toerring.de

+ Reply to Thread