[20] C language learning record linking process

problem

Each C language source file project production target file is compiled, how these files to generate executable programs?

Linker meaning:

The main role of the linker is to refer to each other between the respective portions of the handle module, such that the module is able to secure the cohesion between.

Static links

By the linker when linking the library of content directly into the executable program.

In Linux to create and use static libraries:

1) compile a static library Source: gcc -o -c lib.c lib.o   (the target file)

2) generate static library files: Ar -q lib.a lib.o     (packaged)

3) Use a static library compiler: gcc main.c lib.a -o main.out (lib.a the equivalent of a file package, called static library)

Dynamic-link (DLL and then find the content runtime)

1) executable at runtime dynamic link library load;

2) the contents of the library into the executable program which will not.

sub1 and sub2 dynamic library is exposed (the useful part) tells the compiler can provide content

In Linux creating and using dynamic libraries:

1) compile a dynamic library Source: gcc -shared -o dlib.c dlib.so   (the target file)

2) dynamic libraries to compile: gcc main.c -ldl -o main.out

3) key system call:

       a> dlopen: Open dynamic library files

       b> dlsym: find dynamic library function call and return address

       c> dlclose: Close dynamic library files

 

summary:

1) refers to the link destination file the final link to the executable program;

2) depending on the connection mode, linking process can be divided into:

       a> static link: direct link object files into the executable program; (for small programs)

       b> 动态链接:在程序启动后才动态加载目标文件;(部分更新应用程序)

Guess you like

Origin blog.csdn.net/haibing_x/article/details/94591377