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.