Below we create a dynamic link library.
Recalling the previous article about the establishment of a static link library, we put these files into a new directory:
Makefile Tiaoshen.c mmc.h xu.c
You can also create your own new documents, which are not mentioned here.
Makefile file, change to
All
GCC Tiaoshen.c-o tiaoshen.o-c-fpic
Gcc-o libtiaoshen.so tiaoshen.o-shared
-fpic is compiled to a location-independent code, which can then be loaded anywhere to execute
-shared means a shared library.
The makefile is then compiled (note the white space in front of the GCC in makefile, which is the TAB key)
Use our Library of links:
You directly include the header file and then use it is not possible, generally you create a. So file is not in the fixed directory it looks for, there are two ways to solve
1, CP Libtiaoshen.so/usr/lib can, this is the system comes with the library function file
2. Use environment variables export ld_library_path= $LD _library_path: (Follow the path of your dynamic library)
Then compile:
GCC xu.c-o shen-ltiaoshen-l.
Then you can run it!
The establishment of C language Dynamic link library