943,695 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 634
  • C++ RSS
Jul 10th, 2008
0

Make problem with implicit rule

Expand Post »
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
C++ Syntax (Toggle Plain Text)
  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:
C++ Syntax (Toggle Plain Text)
  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
C++ Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 23
Solved Threads: 12
Posting Whiz in Training
n.aggel is offline Offline
202 posts
since Nov 2006
Jul 11th, 2008
1

Re: Make problem with implicit rule

Quote ...
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
Reputation Points: 1159
Solved Threads: 285
Posting Virtuoso
vijayan121 is offline Offline
1,606 posts
since Dec 2006
Jul 13th, 2008
0

Re: Make problem with implicit rule

thanks vijayan for your assistance!
sorry for asking the RTFM kind of question...
Reputation Points: 23
Solved Threads: 12
Posting Whiz in Training
n.aggel is offline Offline
202 posts
since Nov 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Looking for a good 5 day C++ class in Bay Area???
Next Thread in C++ Forum Timeline: Error?????





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC