makefile problem

makefile problem

Post by co.. » Tue, 20 Feb 2001 11:32:48



I am new to using the Unix AFS system at my university to compile C
programs.
Unfortunately, I have to learn FAST.

I have an assignment due this week that mimics the buffer cache of Unix
OS.
I have written all the code and compiled at home with MS Visual C++
compiler so I know my code works.
(there are 6 *.c files, and 1 header file)
They are called:   main.c, print.c, search.c, remove.c print.c,
create.c, and buffer.h
In each C source file, I have the #includes for the header files it
needs.

The problem that I am having is with the makefile.
I used the vi editor to create it and here is what it looks like: (The
executable is to be called "getblk")

getblk : main.o create.o insert.o remove.o search.o print.o
            cc -o getblk main.o create.o insert.o remove.o search.o
print.o

main.o : main.c stdio.h string.h buffer.h
            cc -c main.c
create.o : create.c stdlib.h stdio.h buffer.h
            cc -c create.c
remove.o : remove.c stddef.h buffer.h
            cc -c remove.c
search.o : search.c stddef.h stdio.h buffer.h
            cc - c search.c
print.o : print.c stddef.h stdio.h buffer.h
            cc -c print.c
clean :
            rm getblk main.o create.o insert.o remove.o search.o print.o

I called the file "makefile" and to run the make, I was told by my
instructor to type in "make" not "makefile".
(This I do not understand)

Anyway, when I typed "make", I get the error message make:
*** No rule to make target `stdlib.h', needed by `create.o'.  Stop.

So I removed stdlib.h from create.o in the makefile, but I got another
similar message for the next header file.
This was repeated until I removed ALL header files from the makefile.
(not one was left)
It then worked perfectly! How could this be w/o header files in the
makefile?

Why was I getting the error in the first place?
Was a PATH setup wrong?
What should it be and most importantly, how do I do it?

Why did my program compile w/o the header files in the makefile?

 
 
 

makefile problem

Post by David Rubi » Tue, 20 Feb 2001 17:29:34



> The problem that I am having is with the makefile.
> I used the vi editor to create it and here is what it looks like: (The
> executable is to be called "getblk")

> getblk : main.o create.o insert.o remove.o search.o print.o
>             cc -o getblk main.o create.o insert.o remove.o search.o
> print.o

> main.o : main.c stdio.h string.h buffer.h
>             cc -c main.c
> create.o : create.c stdlib.h stdio.h buffer.h
>             cc -c create.c
> remove.o : remove.c stddef.h buffer.h
>             cc -c remove.c
> search.o : search.c stddef.h stdio.h buffer.h
>             cc - c search.c

                 ^^^
Should be "-c"

Quote:> print.o : print.c stddef.h stdio.h buffer.h
>             cc -c print.c
> clean :
>             rm getblk main.o create.o insert.o remove.o search.o print.o

You don't need to make dependencies on standard headers. Remove std*.h and
string.h from your make rules.

Quote:> I called the file "makefile" and to run the make, I was told by my
> instructor to type in "make" not "makefile".
> (This I do not understand)

This is how make works. "make" is the command. It looks for a file of rules
called a makefile named "makefile," "Makefile," "mkfile," or other variations.
See 'man make.'

Quote:> Anyway, when I typed "make", I get the error message make:
> *** No rule to make target `stdlib.h', needed by `create.o'.  Stop.

> So I removed stdlib.h from create.o in the makefile, but I got another
> similar message for the next header file.
> This was repeated until I removed ALL header files from the makefile.
> (not one was left)
> It then worked perfectly! How could this be w/o header files in the
> makefile?

Well, you probably need a dependency on buffer.h, but like I said, you don't
need one for standard header files.

Quote:> Why did my program compile w/o the header files in the makefile?

It built all the files for which there were rules starting with getblk. The rule
for getblk has a dependency on your .o files, so make looked for rules to build
them, and just followed a recursive pattern.

        david

--
FORTRAN was the language of choice
for the same reason that three-legged races are popular.
        -- Ken Thompson, "Reflections on Trusting Trust"

 
 
 

makefile problem

Post by Pete Bre » Wed, 21 Feb 2001 02:28:42


Quote:>I called the file "makefile" and to run the make, I was told by my
>instructor to type in "make" not "makefile".
>(This I do not understand)

make is the program which does the work for you. You can specify a
makefile (of any name) using make -f {filename}, but by default, make
will look for a file in the current directory called Makefile or some
close variant.
Quote:

>Anyway, when I typed "make", I get the error message make:
>*** No rule to make target `stdlib.h', needed by `create.o'.  Stop.

The reason you got this error is that make cannot find the file
stdlib.h in the current directory. If you want to have standard C
headers in your dependency lists, you will need to specify the full
path to the files eg. /usr/include/stdlib.h

Quote:>So I removed stdlib.h from create.o in the makefile, but I got another
>similar message for the next header file.
>This was repeated until I removed ALL header files from the makefile.
>(not one was left)
>It then worked perfectly! How could this be w/o header files in the
>makefile?

The dependencies in the makefile are only there to tell make when a
certain rule needs to be executed. Each rule has a target (the object
file or executable), dependencies and one or more commands. If any of
the dependencies for a given target are newer than the target, then
the commands are executed. If you try running make again, it will see
that your program is now newer than all of its dependencies and will
not recompile or link anything.

Quote:>Why was I getting the error in the first place?
>Was a PATH setup wrong?
>What should it be and most importantly, how do I do it?

>Why did my program compile w/o the header files in the makefile?

Again, the dependencies are only there to tell make when it needs to
execute commands. If the target exists and is newer than its
dependencies then there is no reason to rebuild it. If a dependency is
newer than the target, then the target is rebuilt.

Pete

 
 
 

makefile problem

Post by Micah Cowa » Wed, 21 Feb 2001 04:03:18



> I called the file "makefile" and to run the make, I was told by my
> instructor to type in "make" not "makefile".
> (This I do not understand)

It's because you don't "run" makefile - you run a program called make,
and the first thing /that/ program does is looks for a file named
"makefile" in your current working directory.

Quote:> Anyway, when I typed "make", I get the error message make:
> *** No rule to make target `stdlib.h', needed by `create.o'.  Stop.

> So I removed stdlib.h from create.o in the makefile, but I got another
> similar message for the next header file.
> This was repeated until I removed ALL header files from the makefile.
> (not one was left)
> It then worked perfectly! How could this be w/o header files in the
> makefile?

Header files within a makefile have no effect on compilation - they
only instruct make that the files listed are needed in order to create
the target.  While source files are mandatory (otherwise the target
cannot be built), the header files are there only to tell make that if
the header file gets changed, it should rebuild the target.  Header
files are a good thing to list - but not system header-files, because
these are very unlikely to change, and the make program looks for all
these files in the current working directory, where system headers
aren't located.  This is why it worked when you stripped them.

Quote:> Why did my program compile w/o the header files in the makefile?

Because the compiler knows what header files you need from the
#include directives in your source file.  The compiler doesn't know
anything about makefiles.

Regards,
Micah Cowan

 
 
 

1. SCO make/makefile problem

Hi All,

I'm trying to use the VPATH macro in my makefile on a SCO 3.2.4.2 box.
The manual states:
"If a macro named VPATH is assigned a list of colon separated directory
names, make will search these directories when looking for files with
relative path names, in the same way the shells use the PATH environment
variable."

Make should trace through the specified directories, and use files
matching the requirements of a given make instruction. Right?
Not on MY system.

Can anybody PLEASE suggest why make ignores VPATH completely, and advise
on a fix or work-around? Am I just doing something incredibly stupid?
(Apart from not using a different flavour of Unix?)

Thanks, as ever, in advance

PaulM

2. Input on building new computer please

3. Makefile problem

4. Might I upgrade just /stand?

5. Redirecting a directory to a cgi script in Apache1.2b7

6. makefile problem

7. 401 custom message | how to

8. Makefile problems -- subst inside a prereq.

9. Makefile problems in src from CVS

10. makefile problem

11. library makefile problem ?

12. Module compilation (Makefile) problem between 33 and 34