Makefile question

Discussion in 'C++' started by Matthias Pieroth, Mar 4, 2004.

  1. Hi NG,

    I have the following MakeFile:

    # Compiler
    #---------------------------------------
    CC = g++

    APP = snake-client

    # Compilerflags
    #---------------------------------------
    #CFLAGS += -O2

    # Libraries
    #---------------------------------------
    LIB = -lncurses

    # Sourcedateien
    #---------------------------------------
    SRC = snake-client.cpp CCursesWrapper.cpp

    # Objektdateien
    #---------------------------------------
    OBJ = $(SRC:.cpp=.o)

    $(APP): $(OBJ)
    $(CC) $(OBJ) -o $(APP) $(LIB)

    clean:
    rm *.o

    My problem is, I have a CCursesWrapper.h. I want to add this file to the
    MakeFile, so that it will be included and newly compiled if I change the
    CCursesWrapper.h. How can I do this?

    Thank you

    Matthias
    Matthias Pieroth, Mar 4, 2004
    #1
    1. Advertising

  2. Matthias Pieroth wrote:
    > My problem is, I have a CCursesWrapper.h. I want to add this file to the
    > MakeFile, so that it will be included and newly compiled if I change the
    > CCursesWrapper.h. How can I do this?


    I think you want to recompile CCursesWarpper.o whenever CCursesWarpper.cpp
    or CCursesWrapper.h is changed. So, you simply have to add a rule for
    CCursesWrapper.o like

    CCursesWrapper.o: CCursesWrapper.cpp CCursesWrapper.h
    $(CC) -c -o $@ $< $(LIB)

    if CCursesWrapper.h is located in the current directory (otherwise you have
    to add -I <includedir> to the compiler options, where <includedir> stands
    for the directory of CCursesWrapper.h).

    HTH
    Emanuel
    Emanuel Ziegler, Mar 4, 2004
    #2
    1. Advertising

  3. Re: Makefile question [OFF TOPIC]

    Matthias Pieroth wrote:
    > Hi NG,
    >


    Hi NG,

    this is off-topic for comp.lang.c++. Try posting to comp.programming.

    > I have the following MakeFile:

    ....
    >
    > My problem is, I have a CCursesWrapper.h. I want to add this file to the
    > MakeFile, so that it will be included and newly compiled if I change the
    > CCursesWrapper.h. How can I do this?



    you'll need to add the rule

    $(OBJ) : CCursesWrapper.h
    # no commands...


    However - if you want all this to happen automagically, use MakeXS.

    (shameless plug)

    http://www.makexs.com
    Gianni Mariani, Mar 4, 2004
    #3
  4. Matthias Pieroth

    Jorge Rivera Guest

    Matthias Pieroth wrote:
    > Hi NG,
    >
    > I have the following MakeFile:
    >
    > # Compiler
    > #---------------------------------------
    > CC = g++
    >
    > APP = snake-client
    >
    > # Compilerflags
    > #---------------------------------------
    > #CFLAGS += -O2
    >
    > # Libraries
    > #---------------------------------------
    > LIB = -lncurses
    >
    > # Sourcedateien
    > #---------------------------------------
    > SRC = snake-client.cpp CCursesWrapper.cpp
    >
    > # Objektdateien
    > #---------------------------------------
    > OBJ = $(SRC:.cpp=.o)
    >
    > $(APP): $(OBJ)
    > $(CC) $(OBJ) -o $(APP) $(LIB)
    >
    > clean:
    > rm *.o
    >
    > My problem is, I have a CCursesWrapper.h. I want to add this file to the
    > MakeFile, so that it will be included and newly compiled if I change the
    > CCursesWrapper.h. How can I do this?
    >
    > Thank you
    >
    > Matthias
    >


    You can automate this process somewhat...

    Do a man on mkdepends. Read carefully. It writes rules, but it changes
    your Makefile while doing it. It is nice because it will run a
    preprocessor on your source files and determine all the header files it
    requires. It then proceeds to create rules and append them to your Makefile
    Jorge Rivera, Mar 5, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jose luis fernandez diaz

    Question about simple gmake Makefile

    jose luis fernandez diaz, Apr 29, 2004, in forum: C++
    Replies:
    1
    Views:
    1,271
    Christopher Benson-Manica
    Apr 29, 2004
  2. Dan Bishop

    Python in Makefile Question

    Dan Bishop, Feb 11, 2005, in forum: Python
    Replies:
    4
    Views:
    480
    Bart van Deenen
    Feb 11, 2005
  3. Carson

    Makefile question

    Carson, Jul 4, 2005, in forum: C Programming
    Replies:
    1
    Views:
    313
    Rouben Rostamian
    Jul 4, 2005
  4. Replies:
    2
    Views:
    296
  5. xz

    Makefile question.

    xz, Jan 9, 2008, in forum: C++
    Replies:
    8
    Views:
    370
    Victor Bazarov
    Jan 14, 2008
Loading...

Share This Page