Linux generate dynamic link library so file __linux

Source: Internet
Author: User

How to generate a dynamic link library, i.e.. So file, under Linux.

One
First you need a good compilation tool, compiling directly with the GCC command line is no longer a smart idea, a good environment with a compilation tool is important, I chose Easyeclipse, it integrates the CDT, and can easily write C and C + + programs, which automatically integrates the GCC compiler, Compile the work as long as the compilation of the option to point to compile, convenient and quick.

Now let's talk about how to generate the. So file in the Easyeclipse environment.
1. Select New project and establish a C + + project

2. Select the Shared Library in the Project type option and fill in the project name Pxxx click Finish.

3. Write the program, and then compile will be in debug or release to generate a libpxxx.so file, if not Lib's start tag click on the Project menu properties options, and then in the pop-up interface to the right click Build Artifact page, empty the contents of the output prefix option.

4. If it is a C + + program, notice the prefix of the interface function plus the extern "C" tag, with the following tag in the header file:
#ifdef __cplusplus
#extern "C" {
#endif

Header file Body

#ifdef __cplusplus
}
#endif
If you do not add the above tag, after compiling, the function name in so is not the function name you set when you write the program, the PXXX.O in the debug item in the project file list on the left of the development environment can see the function names in the so file are added a __fi mark after the function name you set. For example, the function name you use is func (), and the function name in so is Func__fi () or another name.


If you must compile directly with the GCC compiler, you will see the following:

Compile C Program:
Gcc-shared-fpic Xxx.c-o xxx.so

Compiling C + + programs:
g++-shared-fpic Xxx.cpp-o xxx.so

Note, write C + + program so file, must pay attention to the 4th, otherwise the function name was changed.

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.