Linux static Link Library and dynamic link library 2: Dynamic Link Library generation

Source: Internet
Author: User

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 ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.