Dynamic library *. so production-linux

Source: Internet
Author: User
Dynamic library *. so production-linuxlinux dynamic library. so basic knowledge production in linux dynamic library *. so. 1. create a dynamic library in linux // so_test.h # include & quot; stdio. h & quot; voidtest_a (); voidtest_ B (); voidtest_c (); // test_a.c # inclu dynamic library *. so production-linux
The basic knowledge of linux dynamic library. so is used to create a dynamic library *. so in linux. 1. create a dynamic library in linux // so_test.h # include "stdio. h "void test_a (); void test_ B (); void test_c (); // test_a.c # include" so_test.h "void test_a () {printf (" this is in test_a... \ n ");} // test_ B .c # include" so_test.h "void test_ B () {printf (" this is in test_ B... \ n ");} // test_c.c # include" so_test.h "void test_c () {printf (" this is in test_c... \ n ") ;}generate a dynamic library: libtest. so # gcc test_a.c test_ B .c test_c.c-fPIC-shared-o libtest. so 2. position of the dynamic library and header file # cp libtest. so/lib/# cp so_test.h/usr/include/3. dynamic library link test program // test. c # include Int main () {test_a (); test_ B (); test_c (); return 0. c. dynamic library libtest. so link to generate the execution file test: # gcc test. c-L. -ltest-o test: whether to test Dynamic Connections. if libtest is listed. so, the connection should be normal # ldd test 4. compile parameter parsing-shared: This option specifies to generate a dynamic connection Library (let the connector generate a T-type export symbol table, sometimes, a weak-connection W-type export symbol is generated. if this sign is not used, external programs cannot be connected, which is equivalent to an executable file.-fPIC: indicates that the code is compiled into a separate position; without this option, the compiled code is location-related. Therefore, during dynamic loading, the code is copied to meet the needs of different processes, rather than truly sharing code segments; -L.: indicates that the library to be connected is in the current directory-ltest: When the compiler searches for a dynamic connected Library-implicit naming rules [Note: libtest. so =-lt Est/libhello. so =-lhello] LD_LIBRARY_PATH: this environment variable indicates the path where the dynamic connector can load the dynamic library. Modify the/etc/ld. so. conf file and call/sbin/ldconfig to achieve the same purpose. However, if you do not have the root permission, you can only use the LD_LIBRARY_PATH output method.

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.