Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Make a Makefile

Reply
Thread Tools

Make a Makefile

 
 
Paminu
Guest
Posts: n/a
 
      02-11-2006
I have the following three files:

link.h
contains my structs and list of functions.

link.c
contains my implementation of the functions

linktest.c
contains my main function that test the program with some values.


If I only make changes in linktest.c there would be no reason to recompile
link.c

The first time I compile the whole program I do:

gcc -c link.c
gcc -o linktest linktest.c tree.o


But when I only edit the linktest.c file there is no reason to run the first
line: "gcc -c link.c"

Is it possible to make that kind of "rule" in a makefile?


I have tried to write the follwoing make file:

treetest: tree.c
gcc link.c -c
gcc -o linktest linktest.c link.o


But this way both the gcc commands gets run each time.



 
Reply With Quote
 
 
 
 
Michael Rasmussen
Guest
Posts: n/a
 
      02-11-2006
On Sat, 11 Feb 2006 21:16:00 +0100, Paminu wrote:

> treetest: tree.c
> gcc link.c -c
> gcc -o linktest linktest.c link.o

Try this instead:

OBJ = link.o linktest.o

all: treetest

treetest: $(OBJ)
gcc $(OBJ) -o treetest

link.o: link.c link.h
gcc -c link.c link.h

linktest.o: linktest.c
gcc -c linktest.c
--
Hilsen/Regards
Michael Rasmussen
http://keyserver.veridis.com:11371/p...rch=0xE3E80917

 
Reply With Quote
 
 
 
 
Michael Rasmussen
Guest
Posts: n/a
 
      02-11-2006
On Sat, 11 Feb 2006 21:16:00 +0100, Paminu wrote:

>
> But this way both the gcc commands gets run each time.

Try this instead:

OBJ = link.o linktest.o

all: treetest

treetest: $(OBJ)
gcc $(OBJ) -o treetest

link.o: link.c link.h
gcc -c link.c link.h

linktest.o: linktest.c
gcc -c linktest.c

--
Hilsen/Regards
Michael Rasmussen
http://keyserver.veridis.com:11371/p...rch=0xE3E80917

 
Reply With Quote
 
Joe Wright
Guest
Posts: n/a
 
      02-11-2006
Michael Rasmussen wrote:
> On Sat, 11 Feb 2006 21:16:00 +0100, Paminu wrote:
>
>
>>treetest: tree.c
>> gcc link.c -c
>> gcc -o linktest linktest.c link.o

>
> Try this instead:
>
> OBJ = link.o linktest.o
>
> all: treetest
>
> treetest: $(OBJ)
> gcc $(OBJ) -o treetest
>
> link.o: link.c link.h
> gcc -c link.c link.h
>
> linktest.o: linktest.c
> gcc -c linktest.c


Really? 'gcc -c link.c link.h' compiling a header? Surely link.c will
have '#include "link.h"' and if not, why not?

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      02-11-2006
Paminu <(E-Mail Removed)> writes:
> I have the following three files:
>
> link.h
> contains my structs and list of functions.
>
> link.c
> contains my implementation of the functions
>
> linktest.c
> contains my main function that test the program with some values.

[snip]
> Is it possible to make that kind of "rule" in a makefile?


This is not a C question. The "make" command comes with
documentation; you should find the answer there. Failing that, try
comp.unix.programmer.

(Quick hint: the answer is yes.)

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      02-11-2006
Joe Wright <(E-Mail Removed)> writes:
> Michael Rasmussen wrote:
>> On Sat, 11 Feb 2006 21:16:00 +0100, Paminu wrote:
>>
>>>treetest: tree.c
>>> gcc link.c -c
>>> gcc -o linktest linktest.c link.o

>> Try this instead:
>> OBJ = link.o linktest.o
>> all: treetest
>> treetest: $(OBJ)
>> gcc $(OBJ) -o treetest
>> link.o: link.c link.h
>> gcc -c link.c link.h
>> linktest.o: linktest.c
>> gcc -c linktest.c

>
> Really? 'gcc -c link.c link.h' compiling a header? Surely link.c will
> have '#include "link.h"' and if not, why not?


And this kind of thing is *exactly* why we discourage answers to
off-topic questions here. (Actually it's only one of a number of
reasons.)

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      02-11-2006
Michael Rasmussen wrote:
> On Sat, 11 Feb 2006 21:16:00 +0100, Paminu wrote:
>
>> But this way both the gcc commands gets run each time.

> Try this instead:
>
> OBJ = link.o linktest.o


<snip>

Can you please take your discussion of Makefiles somewhere appropriate.
Possibly comp.programmer, although I am not certain about that, check
their FAQ and a sample of posts first. Makefiles are not, and never have
been, part of C.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
 
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 in textbook example not work(at stage of make install), plz help eric C++ 2 07-02-2011 05:46 PM
Makefile timestamp check to make file rebuild Jeff C Programming 7 03-07-2008 06:34 PM
how to make linux makefile work in visual c++? chenqy2004@gmail.com C Programming 4 06-03-2005 01:44 AM
Doxygen Task for Ant makefile maintainers Karthik Java 0 04-29-2004 03:58 AM
how to compile .vhd files one by one using makefile MACEI'S VHDL 0 07-10-2003 05:18 PM



Advertisments