MagLite Solitaire Single AAA Cell Flashlight

The perfect technician's flashlight
Click Here!
: : : : : : : :    h o m e   :|:   A l l   i n   G e n e r a l   O u t d o o r s   :|:   M a g l i t e   S a l e s   :|:   m y   r e s u m e   
 L i n u x H e l p  : : : : : : : :
The Make command

The make command allows you to manage large programs or groups of programs. As you begin to write larger programs, you will notice that re-compiling larger programs takes much longer than re-compiling short programs. Moreover, you notice that you usually only work on a small section of the program (such as a single function that you are debugging), and much of the rest of the program remains unchanged.

The make program aids you in developing your large programs by keeping track of which portions of the entire program have been changed, compiling only those parts of the program which have changed since the last compile.

A simple compilation

[Image unavailable]

Compiling a small C program requires at least a single .c file, with .h files as appropriate. Although the command to perform this task is simply cc file.c, there are 3 steps to obtain the final executable program, as shown:

  1. Compiler stage: All C language code in the .c file is converted into a lower-level language called Assembly language; making .s files.
  2. Assembler stage: The assembly language code made by the previous stage is then converted into object code which are fragments of code which the computer understands directly. An object code file ends with .o.
  3. Linker stage: The final stage in compiling a program involves linking the object code to code libraries which contain certain "built-in" functions, such as printf. This stage produces an executable program, which is named a.out by default.

Dependencies

The principle by which make operates was described to you in the last section. It creates programs according to the file dependencies. For example, we now know that in order to create an object file, program.o, we require at least the file program.c. (There may be other dependencies, such as a .h file.)

This section involves drawing what are called "dependency graphs", which are very similar to the diagrams given in the previous section. As you become proficient using make, you probably will not need to draw these diagrams, but it is important to get a feel for what you are doing.

Dependency graphs

[Image unavailable]

This graph shown in the figure is a program which is made up of 5 source files, called data.c, data.h, io.c, io.h, and main.c. At the top is the final result, a program called project1. The lines which radiate downwards from a file are the other files which it depends on. For example, to create main.o, the three files data.h, io.h, and main.c are needed.

How dependency works

[Image unavailable]

Suppose that you have gone through the process of compiling the program, and while you are testing the program, you realize that one function in io.c has a bug in it. You edit io.c to fix the bug.

The figure above shows io.c outlined in red. By going up the graph, you notice that io.o needs to be updated because io.c has changed. Similarly, because io.o has changed, project1 needs to be updated as well.

How does make do it?

[Image unavailable]

The make program gets its dependency "graph" from a text file called makefile or Makefile which resides in the same directory as the source files. Make checks the modification times of the files, and whenever a file becomes "newer" than something that depends on it, (in other words, modified) it runs the compiler accordingly.

For example, the previous page explained io.c was changed. If you edit io.c, it becomes "newer" than io.o, meaning that make must run cc -c io.c to create a new io.o, then run cc data.o main.o io.o -o project1 for project1.

Separate compilation

[Image unavailable]

The steps taken in creating the executable program can be divided up in to two compiler/assembler steps circled in red, and one final linker step circled in yellow. The two .o files may be created separately, but both are required at the last step to create the executable program.

You can use the -c option with cc to create the corresponding object (.o) file from a .c file. For example, typing the command: cc -c green.c will not produce an a.out file, but the compiler will stop after the assembler stage, leaving you with a green.o file.

Separate compilation steps

[Image unavailable]

The three different tasks required to produce the executable program are as follows:

  • Compile green.o: cc -c green.c
  • Compile blue.o: cc -c blue.c
  • Link the parts together: cc green.o blue.o
For example, it is important to note that in order to create the file, green.o, the two files, green.c and the header file common.h are required. Similarly, in order to create the executable program, a.out, the object files green.o and blue.o are required.

 L i n u x   W o r l d   N e w s   : : : : : : : :


What in the hell is a KrnlPanic? Well, a KrnlPanic is me! Actually, let's start with "What is a kernel?". The kernel is the core of your operating system (OS), whether your OS is Linux, Unix or windows. The kernel takes care of all process management (what program runs and when), memory management (which parts of memory get used for what) and also, the kernel takes care of interfacing the OS with your computer's hardware (disk drives, sound card, modem, network card, etc).

Now...since the kernel is doing all of these extremely important jobs, it stands to reason that if it has an error, it will be a Bad Thing(tm). If you use windows, you know a kernel panic as a "BSOD" or Blue Screen of Death. Or how about "Invalid Page Fault in KERNEL32.DLL". I'm sure you've probably seen both of those. In Linux, a Kernel Panic is normally plainly stated so. At boot time is when you will see most linux panics. I have yet to see a linux kernel panic while the system is running. You may have seen "Kernel Panic: init not found" or "Kernel Panic: VFS unable to mount root fs on 2:00". All of these previously listed errors are because of something that happened to the kernel that it couldn't handle, whether it was an access to an invalid memory location or the inability to find the initialization files it requires.

I hope that sufficiently explains things. Oh yeah...KrnlPanic is also my name ;-)

- Rick

 S l a s h d o t / F r e s h m e a t   : : : : : : : :
Slashdot and Freshmeat Headlines at 1283543705 (Unixtime)

Slashdot.org Home

o Where Does Dell Go After Losing 3Par?
o Anti-Google Video Runs In Times Square
o The Push For Colbert's "Restoring Truthiness" Rally
o <em>Duke Nukem Forever</em> Back In Development
o New Malware Imitates Browser Warning Pages
o Flawed iTunes Stands Out Among Apple's Products
o Northrop Grumman Says 'I'm Sorry' For Virginia IT Outage
o Major Battle Brewing Between French Gov't and ISPs
o <em>Hurt Locker</em> File-Sharing Subpoenas Begin
o HP Backs Memristor Mass Production
Freshmeat.net Home

Freshmeat headlines seem to be having problems. Will get this working again soon.
 
Search Slashdot:
Search Freshmeat:
Search for linux books or other merchandise @ Amazon.com

Search:
Keywords:
In Association with Amazon.com

Google
: : : : : : : :  K r n l P a n i c   : : : : : : : :
Disclaimer: The documents on this site are to be taken as-is, and I accept no responsibility for damages that may occur from errors or omissions in any of the documents on this site or referred to by this site. By using any of these help documents, you agree to this disclaimer.          ***This site best viewed at 1024x768 or better screen resolution.***