Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Makefile question

Reply
Thread Tools

Makefile question

 
 
Matthias Pieroth
Guest
Posts: n/a
 
      03-04-2004
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

 
Reply With Quote
 
 
 
 
Emanuel Ziegler
Guest
Posts: n/a
 
      03-04-2004
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
 
Reply With Quote
 
 
 
 
Gianni Mariani
Guest
Posts: n/a
 
      03-04-2004
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


 
Reply With Quote
 
Jorge Rivera
Guest
Posts: n/a
 
      03-05-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Makefile question. xz C++ 8 01-14-2008 10:00 PM
a question in makefile jut_bit_zx@eyou.com C++ 2 12-19-2006 02:10 PM
Makefile question Carson C Programming 1 07-04-2005 08:08 AM
Python in Makefile Question Dan Bishop Python 4 02-11-2005 02:41 PM
Question about simple gmake Makefile jose luis fernandez diaz C++ 1 04-29-2004 03:17 PM



Advertisments