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

| |
| +----func.h
| |
| +------ func.c
| +------ main.c

and here are the contents of the files:


float hey(float a, float b);


#include "func.h"

float hey(float a, float b)
	return a+b;


#include "func.h"
#include <stdio.h>

int main()
	printf("%f\n", hey(4.4,4.4) );

	return 0;

and here is the makefile, where i try to use builtin rules to
reduce the size of it

vpath %.c src
vpath %.h headers

CPPFLAGS = -I headers

simple: main.o func.o

main.o: func.h

func.o: func.h

the problem is that when i run gnu-make i only get:

cc  -I headers  -c -o main.o src/main.c
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

# Implicit Rules





%: %.o
#  commands to execute (built-in):
	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@

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

any ideas will be appreciated

8 Years
Discussion Span
Last Post by n.aggel

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/manual/make.html#Implicit-Rules


thanks vijayan for your assistance!
sorry for asking the RTFM kind of question...:(

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.