Simple makefile question

Simple makefile question

Post by Gaur » Sun, 10 Nov 2002 01:54:16



Hi,

I have a file test.c that includes foo.h. Implementation for foo.h is in foo.c

Is this the correct makefile

********************

test : test.o
     g++ -o test test.o
test.o : test.c
     g++ -c test.c

**************************

Do I have to also compile foo.c ???

Thanx,
Gaurav

 
 
 

Simple makefile question

Post by Zoran Cutur » Sun, 10 Nov 2002 02:00:37



Quote:> Hi,

> I have a file test.c that includes foo.h. Implementation for foo.h is in foo.c

> Is this the correct makefile

> ********************

> test : test.o
>      g++ -o test test.o
> test.o : test.c
>      g++ -c test.c

> **************************

> Do I have to also compile foo.c ???

If test.c (why do you compile .c-files with a c++ compiler?)
calls functions declared in foo.h but defined in foo.c you should
be compiling foo.c too and test will be depending on both test.o
and foo.o:

#**************************
test : test.o foo.o

%.o : %.c

#**************************

will just do it for he first, but make can probably do a lot more
for you.

--

"LISP  is worth learning for  the profound enlightenment  experience
you will have when you finally get it; that experience will make you
a better programmer for the rest of your days."   -- Eric S. Raymond

 
 
 

Simple makefile question

Post by Barry Margoli » Sun, 10 Nov 2002 02:01:51




>I have a file test.c that includes foo.h. Implementation for foo.h is in foo.c

What do you mean by "implementation for foo.h"?  Does test.c use functions
that are defined in foo.c, and whose prototypes are in foo.h?  I'll assume
below that this is what you mean.

Quote:

>Is this the correct makefile

>********************

>test : test.o
>     g++ -o test test.o
>test.o : test.c
>     g++ -c test.c

>**************************

>Do I have to also compile foo.c ???

Yes.  And you need to link it with test.o to create test.  Your makefile
should be:

test: test.o foo.o
        g++ -o test test.o foo.o
test.o: test.c foo.h
        g++ -c test.c
foo.o: foo.c foo.h
        g++ -c foo.c

The foo.o dependency on foo.h is needed if there are any structure or class
definitions in foo.h.  If it just contains prototypes for the functions in
foo.c, you don't need that.

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

Simple makefile question

Post by Paul D. Smit » Sun, 10 Nov 2002 03:17:16


  g> I have a file test.c that includes foo.h. Implementation for foo.h
  g> is in foo.c

  g> Is this the correct makefile

  g> ********************

  g> test : test.o
  g>      g++ -o test test.o
  g> test.o : test.c
  g>      g++ -c test.c

Why are you compiling C files with a C++ compiler?  Not a good idea.

You need:

  test.o: test.c foo.h

so make knows that if foo.h is changed, it has to recompile test.o.

  g> Do I have to also compile foo.c ???

Certainly!

  test: test.o foo.o

--
-------------------------------------------------------------------------------

 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
   These are my opinions---Nortel Networks takes no responsibility for them.

 
 
 

Simple makefile question

Post by Frank Schmit » Thu, 14 Nov 2002 21:13:12



> Hi,

> I have a file test.c that includes foo.h. Implementation for foo.h
> is in foo.c

> Is this the correct makefile

> ********************

> test : test.o
>      g++ -o test test.o
> test.o : test.c
>      g++ -c test.c

> **************************

You might want to give your executable another name, since test is a standard
Unix command (typical newbie mistake: "I compiled and ran my test program, but
it doesnt't do anything!!!" :-)

HTH & kind regards
frank

--
Frank Schmitt
4SC AG          phone: +49 89 700763-0
                e-mail: frankDOTschmittAT4scDOTcom

 
 
 

1. simple Makefile question


I see, thanks! Can anyone please advise me how to modify my Makefile
to distinguish compiler flags between the debug and final versions?

           ^^^^^^^^ how then since the files to compile are the same?

Greetings
Alex

--
russkaya literatura v ------ http://www.simplex.ru/lit.html
internete http://www.friends-partners.org/~afarber/lit.html
java preferans ------------ http://www.simplex.ru/pref.html
besplatnye kommercheskie ob'yavleniya http://www.simplex.ru

2. About 'jiffies'

3. Makefile question (simple!)

4. New Dell: annoying sound problem

5. A simple question deserving a simple answer

6. FSP namelen typo (fix)

7. a simple sed question ( there all simple :> )

8. Apache API question

9. Simple question from simple user

10. Simple FTP question (very simple)

11. simple question about simple code

12. Simple question for us simple minded.

13. Simple question - simple answer?