Linux Shared Libraries so file

Source: Internet
Author: User

The so file is similar to the DLL file under Windows. even though different processes call the same so file, the shared library does not enable communication between different processes because the same so is loaded into different memory spaces by different processes.  So file compilation method:The main function is not required in the source file of the-so file, and will not be executed even if there is one. -GCC needs to add -fpic option when compiling, so that GCC can produce location-independent code. $ (CC)-shared-o $ (EXEC) $ (OBJS) -At link time GCC uses the -shared option, which indicates that a shared library file is generated. $ (CC)-wall-g-fpic-o [email protected]-C $< -the Shared library file name starts with Lib and has a. so extension.  use the so file to also provide a header file in the following format:#ifndef Test_h_#define TEST_H_**********#endif  How to use the so file
-for Linux to find the location of so files, you need to add the export ld_library_path= $LD _library_path:. Bash_profile in. , and let it take effect. -or put so files into the Linux system directory/usr/lib/, but not recommended. -To use the so file in a C file, you first need an # include related header file. adding the-l parameter to the-GCC link indicates the so file storage path, and the-l parameter indicates the so filenamesuch as Gcc-l-ltest-o a A.O-L. is searching for so files under the current path-ltest is the library file to link to libtest.so when calling the C language shared library file in C + + files, you need to modify the function declaration: add extern "C" to the header file, or you will get an error when sharing the library with g++ link. #ifndef Share_h_#define SHARE_H_ extern "C" int max (int a, int b); extern "C" int Add (int a, int b);#endifto be compatible with C + + and C hybrid programming, you can improve the#ifndef Share_h_#define SHARE_H_  #ifdef __cplusplus extern "C" { #endifint max (int a, int b);int Add (int a, int b);  #ifdef __cplusplus } #endif#endif/* Test_h_ * /

Linux Shared Libraries so file

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.