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.