Dynamic Link Library is a common software component technology that provides basic services in a variety of operating systems. For example, the Win32 kernel is composed of three DLL files. This technology is also implemented in the Linux operating system, that is, the standard ojbect object of Linux, and the corresponding file extension is. So.
The following is a simple example to introduce Linux Standard objects.
Void show ()
{
Printf ("standard object by gashero/N ");
}
Save as the myso. c file and compile it as follows:$ Gcc-FPIC-shared-O libmyso. So myso. C.
Execute the command to generate a libmyso. So file. According to the naming convention of the Linux Standard object, you should add the "lib" prefix before the library name, although not required. The compile switch-FPIC indicates that function symbols can be redirected, and-shared indicates that the compilation result is a standard object.
The following code callsProgram:
Int main ()
{
Printf ("invoke my so/N ");
Show ();
Return 0;
}
Save as invoke. C and compile it according to the GCC switch below:$ Gcc-O test invoke. C./libmyso. So. Compile and generate the test executable file. The last line of the above compilation condition must be the called standard object file name. Note that the path must be included. If you only use libmyso. So, make sure that the file is under the accessible path. In this example, the file name "./libmyso. So" is in the current path and the relative path is used.
Test results:
$./Test
Invoke my so
Standard object by gashero
Http://www.cppblog.com/mydriverc/articles/33164.html ()