next next up down toc toc Src mail

all, section 3.4.

3.4.  C && Local Libraries

First: Include File

 1      /*
 2       *
 3       *      Tue Feb  3 12:43:58 EST 1998
 4       *      (c) Hans-Peter Bischof
 5       *      SUNY/Oswego
 6       *
 7       *      Module:         hp_lib.h
 8       *      Description:    simple library
 9       */
10      
11      #ifndef HP_LIB_H
12      #define HP_LIB_H
13      
14      #include <stdio.h>
15      #include <stdlib.h>
16      
17      void   cp(const FILE * source, const FILE * target );
18      FILE * hp_open( const char * fn, const char * mode );
19      
20      #endif
21      

Second: Source File

 1      /*
 2       *      Tue Jan 20 09:39:05 EST 1998
 3       *      (c) hpb
 4       *      Module:         3_hp_lib_use.c
 5       *      Description:    copy source target
 6       */
 7      
 8      #include "hp_lib.h"
 9      
10      int main (int argc, char * argv[])
11      {
12      FILE * source;
13      FILE * target;
14      
15              if (argc !=  3) {
16                      printf("%s: %s source-file target_file\n",
17                      argv[0], argv[0]);      
18                      exit(1);
19              }
20              
21              cp( source = hp_open( argv[1], "r" ),
22                  target = hp_open( argv[2], "w" ) );
23              fclose((FILE *)source);
24              fclose((FILE *)target);
25      
26              return 0;
27      }

Third: Create Library

% gcc -c -Wall  hp_lib.c
% ar rcv hp_lib.a  hp_lib.

Fourth: Use Library

% gcc hp_lib_use.c hp_lib.a

See also ar(1).


back next up down toc toc Src mail


Created by unroff & hp-tools. © by Hans-Peter Bischof. All Rights Reserved (1998).

Last modified: 08/May/98 (11:53)