c++ - 谁能简单明白易懂说明一下.a .o .so 这几个文件到底啥区别
高洛峰
高洛峰 2017-04-17 13:52:39
0
4
695

谁能简单明白易懂说明一下

  1. .a

  2. .o

  3. .so

这几種文件到底啥区别 与 联系

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(4)
伊谢尔伦

1. It is a static library similar to lib under NT.
2. It is an object file. It is the semi-finished product when compiled into a program.
3. It is a dynamic library similar to DLL under NT

洪涛

Create static library.a and dynamic library.so on Linux

We usually make some public functions into function libraries for use by other programs.
Function libraries are divided into static libraries and shared libraries:
1. Static function library
The name of this type of library Generally, it is libxxx.a.
The file compiled using the static function library is relatively large, because all the data of the entire function library will be integrated into the target code.
The advantage is obvious, that is, the compiled execution program does not External function library support is required, because all functions used have been compiled in.
Of course, this will also become a disadvantage. If the static function library changes, then your program must be recompiled.
For example, PHP configure parameter --enable-mbstring=static (default),
The generated mbstring.a is statically linked to the binary program php, php-fpm, php-cgi, libphp.so.
2. Shared function library
The name of this type of library is usually libxxx.so.
Compared with static function libraries, shared function libraries are not compiled into the target code during compilation.
When the program executes the relevant function, it is not compiled into the target code. Call the corresponding function in the shared function library, so the executable file generated by the shared function library is relatively small.
Since the shared function library is not integrated into your program, but is dynamically applied for and called when the program is running, so Corresponding libraries must be provided in the running environment of the program.
Changes to the shared function library do not affect your program, so it is more convenient to upgrade the shared function library.
For example, PHP's configure parameter --enable-mbstring=shared , the generated mbstring.so is a shared library.
In addition, use phpize to generate the configure file of the PECL extension library, and then compile it with make. The generated mbstring.so is also a shared library.

--enable-static generates static library a file
--enable-shared generates shared library so file

Use ar to package .o files (obj object files, target files) to generate .a shared libraries:
ar -r libname.a name.o
ar -t libname.a visible name.o

Peter_Zhu

Tell me briefly

.o file

The

.o file is a binary file compiled from the source code.
You must first understand the process from source code to executable file. Take a simple add function source file as an example.

int add(int a,int b)
{
    return a+b;
}

First preprocess into .i file
gcc -E add.c -o add.i
and then compile into assembly file
gcc -S add.i -o add.s
and then assemble into binary .o file
gcc -c add.s -o add.o

Okay, now .o the file is out. It is the product of C/C++ compilation, because C/C++ compilation is unit compilation. Each .c/.cpp file is a compilation unit. After all units are compiled, they are connected into a completed program.

.a file

.a files are essentially .o files packed into a package. It is generally called a static library file. When it is used, the effect is the same as using the .o file.

.so file

The

.so file is different. It is not a simple .o file packed into a package. It is an ELF format file, which is a Linux executable file.
.soFiles can be used for sharing by multiple processes (only position-independent), so they are also called shared library files. When the program uses it, it will be mapped to a certain place in its own process space at runtime, which is not in the program that uses it.

阿神

.o is the smallest compilation unit.
.a is a set of .o files packaged into
.so, which is similar to an executable program except that there is no main function.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!