The fun. C, fun. H, hello. C, hello. H, and Main. c dynamic library functions are all in fun. C and hello. C.
Fun. C:
Int add (int A, int B)
{
Return A + B;
}
Fun. h:
# Ifndef _ fun_h_11
# DEFINE _ fun_h_11
Int add (int A, int B );
# Endif
----------------------------
Hello. C:
# I nclude <stdio. h>
Void output (char * ss)
{
Printf ("Hello % s/n", SS );
}
Hello. h
# Ifndef hello_h_111
# Define hello_h_111
Void output (char * ss );
# Endif
----------------------------
Main. C:
# I nclude <stdio. h>
# I nclude "Hello. H"
# I nclude "fun. H"
Void
Main ()
{
Output ("world ");
Printf ("test value: % d/N", add (1, 2 ));
}
To create and install a dynamic library using libtools:
(1)
Libtool -- mode = compile gcc-g-o-c hello. c
Libtool -- mode = compile gcc-g-o-c fun. c
Libtool -- mode = compile gcc-g-o-c main. c
# Generate their respective o files
(2)
Libtool -- mode = link GCC-g-o libhello. La hello. Lo fun. Lo-rpath/usr/local/lib-LM
# Connecting to a dynamic library file
(3)
Libtool -- mode = link GCC-g-o test main. O libhello. La-LM
# Generate the executable file test
(4)
Libtool -- mode = install CP libhello. La/usr/local/lib/libhello. La
Libtool -- mode = install-C libhello. La/usr/local/lib/libhello. La
Libtool-n -- mode = finish/usr/local/lib
Libtool install-C test/usr/local/bin/test
# Install a dynamic library
Then you can run/usr/local/bin/test. Of course, you can set the path as needed. This is a manual process and the MAKEFILE file is written as follows:
Objs = fun. O hello. o
Lo_objs = Main. Lo fun. Lo hello. Lo
Package_version =
Libdir =/usr/local/lib
ALL: Test
Install: libhello. La
Test: libhello. La main. o
Libtool -- mode = link GCC-g-o test main. O libhello. La-LM
Libhello. La: $ (objs)
Libtool gcc-g-o libhello. La $ (lo_objs)-rpath $ {libdir}-lm-version-Info $ {package_version}
Main. O: Main. c fun. h hello. h
Libtool -- mode = compile gcc-g-o-c main. c
Fun. O: Fun. c fun. h
Libtool -- mode = compile gcc-g-o-c fun. c
Hello. O: Hello. c hello. h
Libtool -- mode = compile gcc-g-o-c hello. c
Clean:
@ RM-f obj/* lib *. *~ * Core *. Lo *. O *. La
@ RM-RF. libs