Python, compilation interpretation, dynamic library static library, compilation process, header file to understand

Source: Internet
Author: User

Learning the language of Python first to understand what is compiled and explained, what is the connection, what is the dynamic library and the static library,

What is compilation:

Compilation is the first high-level language design program translated into binary machine language, and then the CPU directly executes the machine code on it. a translation to be executed again

Compiled language is fast.

What is the explanation:

The explanation is that the high-level programming language is translated into binary machine language one at a time while the program is running. The side run side translates into binary machine language. So the speed is not compiled quickly. Edge execution Side translation

The advantage of interpretive languages is that they can be cross-platform.

The advantages of the Python language:

Portability, scalability, and embedding

Simple, elegant, clear

High development efficiency with powerful third-party libraries

The disadvantages of the Python language:

Slow speed

Code cannot be encrypted

Multithreading cannot take advantage of Multicore (Gil exists)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++

Static library lib and dynamic library DLLs:

1) First what is a library:

Library (LIB) is a compiled binary code, plus a header file for others to use. It takes time to compile the program! and what is a compilation?

Why use libraries: There are some situations where code needs to be available to others, but we don't want others to see the source. Can be encapsulated in the form of a library, exposing only the header files. and the library file is already compiled binary files, compile the time only need link.

But there are two ways of link: One is static link, the other is dynamic link.

2) Static library Lib: (Linux is called. a)

Static libraries are copied to the target program at compile time and are part of the target program.

The benefit of this is to reduce the external dependencies of the target program.

  The downside is that the target program gets too big.

3) Dynamic Library DLL: (under Linux called. So)

The dynamic library is not copied to the target program when it is compiled, and the target program stores a reference to the dynamic library. The dynamic library is actually loaded when the target program is running.

The Advantage of a dynamic library is that it does not have to be copied to the target program and does not affect the volume of the target program. The same dynamic library can be used by multiple programs. Therefore, the dynamic library is also called as a shared library . Features that are loaded at compile time can be replaced and updated at any time by the dynamic library. There is no need to recompile the code.

The downside of a dynamic library is that it can result in a fraction of the performance penalty. Also makes the target program too dependent on the external environment. Once the environment is missing a dynamic library or the library version is incorrect. Will cause the program to not function properly.

 

4) Summary:

Both dynamic and static libraries are a way to share program code. The difference is in the link stage, the static library is copied into the program, and the program is not related to the time of operation. The dynamic library is not copied to the program during the link phase. Instead, the program is dynamically loaded into memory by the system during the run.

The Advantage of a dynamic library is that it needs to be loaded into memory one at a time, and different programs can share copies of the same dynamic library in memory. So it saves a lot of memory.

Library is the way to share program code, the specific function of modular into a library format, easy to share and use.

Both the dynamic library and the static library are closed source libraries, which can only be used to satisfy a certain function. Does not disclose the internal specific code information.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++

The process of compiling:

Here's the C language, because Python is written in C. The python interpreter is used to execute the. py text file .

Compilation is divided into 4 processes: 1) preprocessing preprocessing, 2) compiling compilation, 3) assembly assemble, 4) Link linking

1) pretreatment preprocessing:

Preprocessing is used to replace all of the include header files and macro definitions with their true content, which is still a text file after preprocessing, but the file size is much larger.

The program or text after preprocessing can be opened with a text editor.

2) Compile (compliation):

The compilation here does not refer to the whole process of the program from the source file to the binary program, but rather the process of converting the preprocessed program into a specific assembly code (assembly).

This process. c files are compiled into. s files.

3) Assembly (Assemble):

The Assembly process converts the assembly code from the previous step to machine code, which produces a file called the target file, which is in binary format.

This step produces a target file for each source file. obj.

4) Link (linking):

The linking process links multiple target texts and required library files to the final executable file (executable file).

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++

About header files:

header files and libraries are actually not the same.

In fact, the main function of the header file is the reuse of multiple code files global variables (functions), prevent the conflict of definitions, to each called function to give a description, which itself does not need to include the program's logical implementation code, it only a descriptive role, the user program only need to follow the interface in the header file declaration To invoke the relevant function or variable, the linker looks for the corresponding actual definition code from the library.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++

Related connections:

What kind of language is Python: https://www.cnblogs.com/gaojun2017/p/6274540.html

Dynamic library and Static library details: https://www.cnblogs.com/striveLD/p/5752010.html

C language Compilation process: https://www.cnblogs.com/CarpenterLee/p/5994681.html

Python interpreter: http://man.chinaunix.net/develop/python/python2.3tut/tut/node4.html

The difference between a header file and a library: 53009795

What is the. obj file: https://www.cnblogs.com/ShadowHanlder/p/4410213.html

Python, compilation interpretation, dynamic library static library, compilation process, header file to understand

Related Article

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.