Make problem with implicit rule

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2006
Posts: 202
Reputation: n.aggel is an unknown quantity at this point 
Solved Threads: 11
n.aggel's Avatar
n.aggel n.aggel is offline Offline
Posting Whiz in Training

Make problem with implicit rule

 
0
  #1
Jul 10th, 2008
hi,

i have the following structure in the "simple application":

application_folder
|
|--makefile
|
+-headers
| |
| +----func.h
|
|
+src
| |
| +------ func.c
| +------ main.c
|
|

and here are the contents of the files:

*func.h
  1. float hey(float a, float b);

*func.c
  1. #include "func.h"
  2.  
  3. float hey(float a, float b)
  4. {
  5. return a+b;
  6. }

*main.c
  1. #include "func.h"
  2. #include <stdio.h>
  3.  
  4. int main()
  5. {
  6. printf("%f\n", hey(4.4,4.4) );
  7.  
  8.  
  9. return 0;
  10. }

and here is the makefile, where i try to use builtin rules to
reduce the size of it
  1. vpath %.c src
  2. vpath %.h headers
  3.  
  4. CPPFLAGS = -I headers
  5.  
  6. simple: main.o func.o
  7.  
  8. main.o: func.h
  9.  
  10. func.o: func.h

the problem is that when i run gnu-make i only get:
  1. cc -I headers -c -o main.o src/main.c
  2. cc -I headers -c -o func.o src/func.c
so basically the built in rule for simple is never run.

To verify that there is a default rule for such cases,
i type gmake --print-data-base > gmake.database.txt
and when i read gmake.database.txt i find
  1. # Implicit Rules
  2.  
  3. %.out:
  4.  
  5. %.a:
  6.  
  7. %.ln:
  8.  
  9. %.o:
  10.  
  11. %: %.o
  12. # commands to execute (built-in):
  13. $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@

so this should work but it doesn't.....

any ideas will be appreciated
-nicolas
Two roads diverged in a wood, and I— I took the one less traveled by, and that has made all the difference.

by Robert Frost the "The Road Not Taken"
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: Make problem with implicit rule

 
1
  #2
Jul 11th, 2008
n is made automatically from n.o by running the linker (usually called ld) via the C compiler. The precise command used is ...

This rule does the right thing for a simple program with only one source file. It will also do the right thing if there are multiple object files (presumably coming from various other source files), one of which has a name matching that of the executable file....

In more complicated cases, such as when there is no object file whose name derives from the executable file name, you must write an explicit command for linking.
from http://www.gnu.org/software/make/man...Implicit-Rules
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 202
Reputation: n.aggel is an unknown quantity at this point 
Solved Threads: 11
n.aggel's Avatar
n.aggel n.aggel is offline Offline
Posting Whiz in Training

Re: Make problem with implicit rule

 
0
  #3
Jul 13th, 2008
thanks vijayan for your assistance!
sorry for asking the RTFM kind of question...
Two roads diverged in a wood, and I— I took the one less traveled by, and that has made all the difference.

by Robert Frost the "The Road Not Taken"
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC