what is the problem about my makefile

D

dolphin

Hi! I am learing makefile recently.Now I have a problem.
I write a very simple program just like "hello world"
I write two makefile for it.One is included in another.
the first is makefile
include mainmake.mk
example:main.o
cc -o example main.o
clean:
rm -f *.o

this is the second makefile named mainmake.mk which is included in
makefile.
main.o:main.c head.h
cc -c -g main.c

when I type make command in shell.Only main.o file is created.The file
main did not be created.What is the problem?I am in redhat 9.0
 
P

Peter Nilsson

Hi! I am learing makefile recently.Now I have a problem.
I write a very simple program just like "hello world"
I write two makefile for it.

The program we can help you with. The makefile aspect is
off topic.
 
R

R Smith

Hi! I am learing makefile recently.Now I have a problem.
I write a very simple program just like "hello world"
I write two makefile for it.One is included in another.
the first is makefile
include mainmake.mk
example:main.o
cc -o example main.o
clean:
rm -f *.o

this is the second makefile named mainmake.mk which is included in
makefile.
main.o:main.c head.h
cc -c -g main.c

when I type make command in shell.Only main.o file is created.The file
main did not be created.What is the problem?I am in redhat 9.0

Off topic, off schmopic, who cares? You need help.

Try this:

cc -o example main.c

You can't compile a .o file. You can say I want to compile a .c program
and call it this (-o).
 
C

CBFalconer

dolphin said:
Hi! I am learing makefile recently.Now I have a problem.
I write a very simple program just like "hello world"
I write two makefile for it.One is included in another.
the first is makefile

include mainmake.mk
example:main.o
cc -o example main.o
clean:
rm -f *.o

this is the second makefile named mainmake.mk which is included in
makefile.
main.o:main.c head.h
cc -c -g main.c

when I type make command in shell.Only main.o file is created.The file
main did not be created.What is the problem?I am in redhat 9.0

That creates main.o, which will be the relocatable object version
of your c file. To create the runnable final file you need to
execute:

cc -o main main.o

which you express (in the make file) as:

main : main.o #the dependency
cc -o main main.o #the command to execute

Note that the commands have a leading tab char.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
 
B

Bill Pursell

I write a very simple program just like "hello world"
I write two makefile for it.One is included in another.
the first is makefile
include mainmake.mk
example:main.o
cc -o example main.o

This is off-topic here, but if you
insert your included makefile by hand,
you'll see that invoking make with no
arguments is equivalent to invoking:
"make main.o" since main.o is the
first target. Try moving the include
line below the example target.
 
C

Chris Torek

dolphin said:
@l77g2000hsb.googlegroups.com:
Hi! I am learing makefile recently. ... [makefile snipped]
when I type make command in shell. Only main.o file is created. The file
main did not be created. What is the problem? I am in redhat 9.0

You want comp.unix.programmer, or a linux-specific newsgroup (although
the former will suffice here).

Off topic, off schmopic, who cares? You need help.

Well, "dolphin" may care, since you have given him an incorrect
answer. :)
Try this:

cc -o example main.c

Although that can be made to work, it is not what he should be
doing in this case.
You can't compile a .o file.

Depending on the system, you *can*, depending on just what one
means by "compile" ... and RedHat Linux is one of those where you
can, and he has done the right things to make the given .o file
"compile-able".

For more information, try comp.unix.programmer.
 
K

Kenny McCormack

You can't compile a .o file.

Depending on the system, you *can*, depending on just what one
means by "compile" ... and RedHat Linux is one of those where you
can, and he has done the right things to make the given .o file
"compile-able".[/QUOTE]

I think the statement "You can't compile a .o file." is technically
true, but moot. It is much akin to the statement that you can't bake a
cake. This last is true, since at the point in time when it is baking,
it is not a cake, but merely a bunch of ingredients mixed together in a
pan. Only when the baking is finished, is it a cake.

But I think most of us would agree that both statements are pretty silly
(though I daresy they might well appeal to the idiots^Wpedants in this ng)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top