Introduction to libraries.

Many applications programs require tasks to be performed more than once, possibly in different parts of the code. Within a single application, we create functions which execute these tasks, and call them whenever we need to perform the tasks they define. Libraries allow us to extrapolate this concept to multiple applications so that a task which is used in more than one program can be reused, rather than rewritten, in each program.

Suppose we have the following program, and that we would like to reuse the code for the function func() in other programs. Libraries let us take functions which we would like to reuse and store them with other functions that we would like to reuse in a single file. When we write an application in which we want to use one of these functions, all we have to do is call it just as main() below calls func(), then link the library with our source code when we compile.


	#include 

	int a_global;

	int func ( int a, int b )
	{
		return (a+b);
	}

	void main (void)
	{
		int a_local = 7;

		a_global = 5;

		printf ( "The result is %d\n", func(a_local, a_global);
	}

In this tutorial, we will talk about organizing source files and objects, and building applications using modular objects and libraries.
This page was last modified .